0

How to keep prompting user to enter input when input is invalid python.

I'm making a text based rpg. I prompt the user to enter a class out of three choices rogue,warrior or ranger. I also made if statements to output a string if one of the choices are chosen. what can I add to keep prompting the user say if the user enters 'mage'.

17th Oct 2018, 3:54 AM
Elijah Mcgrue
Elijah Mcgrue - avatar
2 odpowiedzi
+ 2
Welll...there's the Pythonic way, raising StopIteration (and collecting stats): https://code.sololearn.com/cAP6JETxuE4r/?ref=app But lots of people would probably do this: while True: input... ...handle valid inputs... break on any valid input (done) print error # auto loop without break or this: while True: input... if badInput: # print error, jump back to start continue ...handle input: all bads were caught already # get out of the loop, you had a success break
17th Oct 2018, 4:18 AM
Kirk Schafer
Kirk Schafer - avatar
0
Thanks! this helped me get a solution
17th Oct 2018, 5:13 AM
Elijah Mcgrue
Elijah Mcgrue - avatar