so I am currently learning how to use Python and have been trying to solve a problem of mine where I have an if statement that when an incorrect value is entered I would like it to restart and ask the question again.
I believe a while loop or a for loop will be needed for this however after looking for a while I m just not sure how I would implement it in with this code, therefore if anyone knows I would love to see how.
x = int(input("Pick between 1,2,3,4,5: "))
if x == 1:
print("You picked 1")
elif x == 2:
print("You picked 2")
elif x == 3:
print("You picked 3")
elif x == 4:
print("You picked 4")
elif x == 5:
print("You picked 5")
else:
print("This is not a valid input, please try again")
#Want to go back to asking the start question again
Thanks,
Liam
Aucun commentaire:
Enregistrer un commentaire