2016-04-02 12 views
0

Ich bin wirklich neu in Python und ich versuche zu lernen, indem Sie ein einfaches Spiel. Ich möchte, dass der Benutzer in der Lage ist, seine Aktion einzugeben, und wenn er sich nicht zu weit fortsetzt, werden sie zurück zur Eingabeebene gesendet. Ich habe es so gut wie möglich versucht, aber wenn sie sich nicht mehr "weitermachen", können sie keine der anderen Optionen mehr wählen.Wie mache ich meine Python-Code-Schleife zurück

Hilfe ist willkommen.

print ("How do you proceed?") 
print ("Do you Shout? Look? Continue?") 
action1 = input() 

if action1 == ("Continue"): #Continue to next section 
    print ("You continue on throught the darkness untill you reach a cold stone wall") 
    pass 

elif action1 == "Shout": 
    print ("In the dark noone can hear you scream.") 

elif action1 == ('Look'): 
    print ("'I cannae see anything in the dark' you think to yourself in a braod Scottish accent.") 

while action1 != ("Continue"): 
    print ("Enter your next action.(Case sensitive!!)") 
    print ("Shout? Look? Continue?") 
    action1 = input() #Want this too loop back to start of action menu 

Antwort

0

Sie können den gesamten Prozess in einer Schleife while setzen und brechen aus der Schleife, wenn die Benutzereingabe gilt:

print("How do you proceed?") 

while True:   
    print("Do you Shout? Look? Continue?") 
    action1 = input() 

    if action1 == "Continue": # Continue to next section 
     print("You continue on throught the darkness untill you reach a cold stone wall") 
     break # break out of the while loop 

    elif action1 == "Shout": 
     print("In the dark none can hear you scream.") 

    elif action1 == 'Look': 
     print("'I cannot see anything in the dark' you think to yourself in a broad Scottish accent.") 

    print("Enter your next action.(Case sensitive!!)") 

# You'll land here after the break statement 
Verwandte Themen