剛剛開始學習一點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