Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I loop back to the beginning, when my player chooses option 2 or 3? I have tried to loop, but I don’t know where I can set the while loop, and start to move from the beginning. In other words, restart the game.

and here's my code, but it's not working properly
Python
print ("You are an office worker. You just ended your overnight shift, where you are the only one left in the building. Before leaving, you decide to go to the washroom to do your business. While washing up, you spot a white figure in the mirror. As you looked closely in the mirror, you then realize that a ghost has been hovering over you.")

print ("After realizing that there was a ghost hovering over you, what would you do?")

sc1Option1=print("[1]RUN")
sc1Option2=print("[2]HIDE")
sc1Option3=print("[3]PEEK")
print("")
Option=input("Choose your Option!")
if (Option=="1"):
   sc1Option1=print("Run")
elif (Option=="2"):
   print("Sorry,hiding will not help you to escape.Please restart.")
elif (Option=="3"):
   print("Sorry,peeking will not help you escape.")


what I'm trying to do is:

if the player chooses option 1 - the program will go to the next scenario.
if the player chooses option 2 - the program will show the text "Sorry, hiding will not help you to escape.Please restart." first, and back to the beginning.
if the player chooses option 3 - the program will show the text "Sorry, peeking will not help you escape." first, and let the player re-choose the option again.

What I have tried:

I have tried to loop, but I don’t know where I can set the while loop, and start to move from the beginning. In other words, restart the game.
Posted
Updated 13-Aug-21 21:15pm
Comments
Richard MacCutchan 13-Aug-21 11:25am    
I do not see the point of having options 2 and 3 since they do not allow the user to do anything apart from choose again.

 
Share this answer
 
Comments
Hui xin 2021 13-Aug-21 15:58pm    
Thank you :)
why don't you make it a function????
 
Share this answer
 
solved! thanks for the helped:)

def option_checker():
    program_acceptance = "\033[1;37;m                                Run"
    sc1Option1= "1"
    sc1Option2= "2"
    sc1Option3= "3"
    
    print("\033[1;37;m                                Choose your Option!")
    while True:
        option = input("\033[1;37;m                                Option:  ")
        if option == sc1Option2:
            print("                                Sorry,hiding will not help you to escape.Please restart.")
        if option == sc1Option3:
            print("                                Sorry,peeking will not help you escape.")
        if option == sc1Option1:
            print(program_acceptance)
            break
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900