samedi 28 mars 2015

Checking that input is an integer between 1 and 3 - Python

I want to be able to check that an input is an integer between 1 and 3, so far I have the following code:



userChoice = 0

while userChoice < 1 or userChoice > 3:
userChoice = int(input("Please choose a number between 1 and 3 > "))


This makes the user re-enter a number if it is not between 1 and 3, but I want to add validation to ensure that a user cannot enter a string or unusual character that may result in a value error.


Thanks in advance


Aucun commentaire:

Enregistrer un commentaire