2016-04-02 21 views
0

Python'a gerçekten yeniyim ve basit bir oyun yaparak öğrenmeye çalışıyorum. Kullanıcının eylemlerini girmesini istiyorum, sonra da devam etmeyi seçtiyse, tekrar giriş aşamasına geri gönderilecekler. Bunu mümkün olan en iyi şekilde denedim, ancak "devam etmeme" seçeneğini seçtiklerinde, belirttiğim diğer seçenekleri artık seçemezler.Python kod döngüsüm nasıl geri dönülür

Yardım memnuniyetle karşılanır.

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 

cevap

0

tek bir while döngüye tüm süreci koymak ve kullanıcı giriş geçerli olup olmadığını döngünün çıkabilr:

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