我需要幫助這個數據驗證問題在Python 2.7中,它做我希望它不接受字符串,但它不接受整數,因爲它應該這樣做。Python 2.7的數據驗證
def GetKeyForCaesarCipher():
while True:
key =(raw_input('Enter the amount that shifts the plaintext alphabet to the ciphertext alphabet: '))
try:
i=int(key)
break
except ValueError:
print ('Error, please enter an integer')
return key
「你的意思是什麼都行不通」在這裏是一個有建設性的問題。我們需要知道代碼應該做什麼,以及它實際正在做什麼來正確診斷您的問題。下面,Martijn假設你想從函數中返回整數,但是這篇文章沒有辦法知道這個(合理的)假設是否正確。 – mgilson 2013-03-07 15:46:34