Python 2.7 Data Validation
I need help for this data validation problem in Python 2.7, it does what i want it doesn't accept strings however it doesn't accept integers either as it should do. def GetKeyForCa
Solution 1:
It accepts integers just fine, but you are returning the original string value. You should either return i
or assign to key
instead:
key = int(key)
Solution 2:
Martijn's answer is correct, of course, but if you improved your style, you might find debugging easier. Try it like this:
defpromptForInteger(prompt):
whileTrue:
try:
returnint(raw_input(prompt))
except ValueError:
print ('Error, please enter an integer')
defgetKeyForCaesarCipher():
return promptForInteger('Enter the amount that shifts the plaintext alphabet to the ciphertext alphabet: ')
Post a Comment for "Python 2.7 Data Validation"