刚刚开始学习一点python,并由于某种原因,我刚刚放在一起的脚本返回一个数字,如10000000000000000 < 5.我认为这是由于本地不准确与int
键入大值,但我不确定,也许我只是做错了什么!Python比较不正确与大整数
这里是我的(写得不好,我知道)脚本:
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.'
发生这种情况是因为您正在比较字符串。将'firstNum','secNum'和'thirdNum'变成'int's – inspectorG4dget 2014-09-05 05:37:35