I’m currently learning Python, and was wondering something. I’m writing a little text adventure game, and need help with this:
If I write, for example,
example = input("Blah blah blah: ")
if example <= 20 and > 10:
decision = raw_input("Are you sure this is your answer?: ")
what functions can I write that will cause “example = input(“Blah blah blah: “)” to run again? If the user says no to “decision = raw_input(“Are you sure this is your answer?: “)”.
Sorry if I confused you all. I’m a bit of a newbie to Python, and programming altogether.
You are looking for a
whileloop:A loop runs the block of code repeatedly until the condition no longer holds.
We set decision at the start to ensure it is run at least once. Obviously, you may want to do a better check than
decision.lower() == "no".Also note the edit of your condition, as
if example <= 20 and > 10:doesn’t make sense syntactically (what is more than 10?). You probably wantedif example <= 20 and example > 10:, which can be condensed down to10 < example <= 20.