2017-05-28 5 views
-2

Kann jemand erklären, warum das nicht läuft?Warum kann ich am Ende meines Programms keine Eingabe registrieren?

import time 

Start up-Menü

print ("Before you start the game ensure that you are playing in fullscreen to enhance your gaming experience") 
print("") 
print ("") 
time.sleep(1) 

Dieses einfach das Menü starten

ist
print ("Menu") 
print ('Instructions: In this game you will be given a series of paths. Using your best judgment you will choose the best path by using the "1" or "2" number keys, followed by pressing the "enter" button') 
print ('If the wrong path is selected, there will be consequences of either death, or a lower final score.') 
print ('Death will end the game, and you will be forced to start from the beginning of the level.') 
time.sleep(1) 
print ('If you will like to restart, press "r"') 
print ('If you will like to quit, press "q"') 
print ('If you want to play level 1, press "1"') 
print ('If you want to play level 2, press "2"') 
print ('you cannot restart or quit at this time') 
print ('') 
print ('') 
def levelselection(): 
    level="" 
    while level != "1" and level != "2": 
     level = input("Please select a level to play: ") 
     return level 
#This section below is what I have trouble with. It was working before I added "time sleep and after." 
level = levelselection() 
if level == "1": 
    print("Level 1 selected") 
    print ("You and your crew are pinned in the remains of a church on the top floor, along with wounded soldiers. Being fired at by German machine guns, matters will soon only get worse as you see German reinforcements on their way. Find a way to escape with your 9 man crew with minimal casualties.") 
    time.sleep(1) 
    print ("Do you;") 
    print ("1:Order your 6 healthy soldiers to provide cover fire while you try and find a way to escape") 
    time.sleep(1) 
    print ("2:Order 4 soldiers to provide cover fire, while the other two soldiers take care of the wounded and you try and find a way to escape") 
    def path1(): 
     path =="" 
     while path !="1" and path!="2": 
      path = input("Select a path: ") 

Das ist, was ich habe Probleme läuft. Es wird einfach nicht ausgeführt. Es gibt mir auch keine Fehlermeldung.

if path == 1: 

     print ("The crew provided the cover that was needed to protect you, and you were able to safely make it back with two possible options of escape. The wounded soldiers are starting to bleed out.") 
+0

Sie benötigen um dein Problem besser zu erklären. Und Ihr Titel scheint ein anderes Problem zu beschreiben als den Kern der Frage. – Carcigenicate

Antwort

0

ein paar Dinge, die mich schlagen die Manschette aus:

path =="" 

ist ein Bool. es wird wahr oder falsch zurückgeben, aber es wird die Variable Pfad nicht gesetzt ist (das ist, was Sie zu tun scheinen zu wollen)

def path1(): 

Sie die Funktion path1() zu definieren, ohne sie in Ihrem Programm aufrufen. Es wird dafür laufen nie (und fragt nicht für die Eingabe entweder)

+0

also was ändere ich, um es zu beheben? –

+0

@ElyadK Weisen Sie den Pfad zu, anstatt ihn zu vergleichen, und rufen Sie tatsächlich 'path1' auf. – Carcigenicate

0

Ein paar Dinge

if level == "1": 
print("Level 1 selected") 
print ("You and your crew are pinned in the remains of a church on the top floor, along with wounded soldiers. Being fired at by German machine guns, matters will soon only get worse as you see German reinforcements on their way. Find a way to escape with your 9 man crew with minimal casualties.") 
time.sleep(1) 
print ("Do you;") 
print ("1:Order your 6 healthy soldiers to provide cover fire while you try and find a way to escape") 
time.sleep(1) 
print ("2:Order 4 soldiers to provide cover fire, while the other two soldiers take care of the wounded and you try and find a way to escape") 
def path1(): 
    path =="" 
    while path !="1" and path!="2": 
     path = input("Select a path: ") 

def path1() sollte

def path1(path): 
    path =="" 
    while path !="1" and path!="2": 
     path = input("Select a path: ") 

if level == "1": 
    print("Level 1 selected") 
    print ("You and your crew are pinned in the remains of a church on the top floor, along with wounded soldiers. Being fired at by German machine guns, matters will soon only get worse as you see German reinforcements on their way. Find a way to escape with your 9 man crew with minimal casualties.") 
    time.sleep(1) 
    print ("Do you;") 
    print ("1:Order your 6 healthy soldiers to provide cover fire while you try and find a way to escape") 
    time.sleep(1) 
    print ("2:Order 4 soldiers to provide cover fire, while the other two soldiers take care of the wounded and you try and find a way to escape") 
    path = input() 
    if path == '1': 
     print ("The crew provided the cover that was needed to protect you, and you were able to safely make it back with two possible options of escape. The wounded soldiers are starting to bleed out.") 
    path1(path) 

sein eigenes Ding zum Beispiel Dies funktioniert. Das Problem mit dem alten Code war, dass path1 in der if-Anweisung war, Pfad keinen Wert hat,

if path == 1: 

if path =='1': 

sein sollte und path1 ein Argument zu nehmen hat

Verwandte Themen