首页 > 编程语言 > 详细

python-第五章习题

时间:2019-10-10 13:07:02      阅读:94      评论:0      收藏:0      [点我收藏+]

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))

 

 

 

 

python-第五章习题

原文:https://www.cnblogs.com/sunblingbling/p/11647242.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!