Python 2.7数据验证

use*_*562 0 python validation

我需要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
Run Code Online (Sandbox Code Playgroud)

Mar*_*ers 5

它接受整数很好,但是你返回原始的字符串值.你应该返回i或分配给key:

key = int(key)
Run Code Online (Sandbox Code Playgroud)