刚刚开始学习一些python,出于某种原因,我编写的脚本返回一个数字,比如100000000000000<;5。我假设这是由于int
类型在很大的值下的本地不准确,但我不确定,也许我只是做错了什么!在
以下是我的剧本(我知道,写得不好):
def checkValue(n):
while True:
if n == '':
print 'You didn\'t enter anything!'
return False
else:
try:
n = int(n)
except ValueError:
print 'That is not an integer!'
return False
else:
break
return True
while True:
firstNum = raw_input('Enter the first number: ')
if checkValue(firstNum) == False:
continue
else:
break
while True:
secNum = raw_input('Enter the second number: ')
if checkValue(secNum) == False:
continue
else:
break
while True:
thirdNum = raw_input('Enter the third number: ')
if checkValue(thirdNum) == False:
continue
else:
break
if thirdNum > secNum and thirdNum > firstNum:
print 'The third number is the biggest.'
elif secNum > firstNum:
print 'The second number is the biggest.'
else:
print 'The first number is the biggest.'
{{you正在转换“{cd2>中的输入}”。但是在比较时使用输入的字符串值。所以可以在输入阶段转换“firstNum”、“secNum”和“thirdNum”。看到区别了。在
您需要将原始输入
firstNum
等转换为带有intfirstNum = int(firstNum)
的整数。在相关问题 更多 >
编程相关推荐