Python Forum

Full Version: How to re run lines in python?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am making a text based game in python 3.7.2 but if users type somtheing wrong I want it to re run a line and let them try again but it doesn't work.I have been cracking my head and I can't figure it out.Here is the script so far:

print("Hello I hpoe that everything is working.If you see this everything probably works.Type MENU to see the options.")
options = input()
if options == 'MENU' or options == 'Menu' or options == 'menu':
    print("START                        NOTE-TYPE TO INTERACT")
game_start = input()
if game_start == 'START' or 'START' or 'Start':
    print("Ok Let's begin with the game.")
print("LOADING STARTING IN 7 SECONDS")   
import time
time.sleep(7)
for k in range(1000):
    print(k)
print('LOADED')
print("You are on a field and you see a mansion in the distance.You can't remember anything.There is somtheing shiny on the floor.")
You can use a while loop similar to code below from the python docs tutorial here
def ask_ok(prompt, retries=4, reminder='Please try again!'):
    while True:
        ok = input(prompt)
        if ok in ('y', 'ye', 'yes'):
            return True
        if ok in ('n', 'no', 'nop', 'nope'):
            return False
        retries = retries - 1
        if retries < 0:
            raise ValueError('invalid user response')
        print(reminder)
I have loked at the wiki but I still do not not what to do help... Cry Cry Cry
We need something more than "I don't know what to do." Yoriz posted a good example of code to repeat a question multiple times until you get a valid yes or no answer. What do you not understand about that? How does it not fix your problem.
Sorry,
I don't know hot implement that into my code
Sorry I got it now Smile Smile Smile