My code looks like this:
while variable > 20 or variable < 1 or variable etc etc:
variable = input()
if variable > 20 or variable < 1 or variable etc etc:
print("The variable should be between 1 and 20.")
The thing is, I don't want to have to repeat myself in the if statement when I'm checking for the variable to fit a lot of criteria. Is there a shorter/more elegant way or checking the variable with the same criteria at both points?
Aucun commentaire:
Enregistrer un commentaire