a = (math.ceil(6*random.random()))
b = (math.ceil(6*random.random()))
c = (math.ceil(6*random.random()))
CD = (10)
e = (a+b+c)
print ("a = {0}" .format (a))
print ("b = {0}" .format (b))
print ("c = {0}" .format (c))
print ("a+b+c = {0}" .format (e))
if a+b+c > CD:
print ("Maior que {0}" .format(CD))
else:
print ("Menor que {0}" .format(CD))
我想允许用户更改变量CD。我该怎么做
使用
input()
函数:函数的作用是:返回一个字符串到CD,不管你是在控制台中输入int,float,boolean还是string,因为你的工作与算术运算有关,所以我把它转换成float,但是你也可以使用
如果您试图输入一个浮点值,但是如果您显式地定义原始输入()函数的类型,或者如果您在控制台中输入字母字符作为输入,那么它将引发一个错误:)
在Python3.x中尝试以下方法:
对于python 2.x:
相关问题 更多 >
编程相关推荐