我需要帮助这个数据验证问题在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