python-第五章习题

5.2

def isOdd(x):
    if(x%2==0):
        return False
    return True
x=eval(input(""))
print(isOdd(x))

5.3

def isNum(s):
    try:
        s=type(eval(s))
        if(s==type(1)):
            return True
        elif(s==type(1.0)):
            return True
        elif(s==type(1+j)):
            return True
    except:
        return False
s=input("")
print(isNum(s))

5.4

def multi(*n):
    result=1
    for i in n:
        result=result*int(i)
    return result
x=input("").split()
lst= [int(i) for i in x]
print(multi(*lst))

5.5

def isPrime(x):
    try:
        x=int(x)
        if x==1:
            return False 
        else:
            for i in range(2,x):
                if x%i==0:
                    return False
                else:  
                    return True
    except:
        print("请输入整数")

x=input("")

print(isPrime(x))

 

 

 

 

posted @ 2019-10-10 12:33  水晶bingbing  阅读(533)  评论(0编辑  收藏  举报