2017-05-28 4 views
-2

誰もこれがなぜ動かないのか説明できますか? 私のプログラムの終わりに、なぜ入力を登録できないのですか?

import time 

これはこれは私がトラブルが実行されているものです単に起動メニュー

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: ") 

あるメニュー

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

起動

。単に実行されません。エラーメッセージも表示されません。

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

を取るために持っていなければなりませんでしたということでしたあなたの問題をより良く説明する。あなたのタイトルは質問の本文とは異なる問題を記述しているようです。 – Carcigenicate

答えて

0

カフを私を打ついくつかのこと:

path =="" 

はブール値です。あなたのプログラムでそれを呼び出すことなく、関数パス1を()を定義

def path1(): 

(あなたがやりたいように見える何である)、それは、TrueまたはFalseを返しますが、それは変数のパスを設定しません。それは実行されませんそのためだろう(そしてどちらかの入力を要求しません)

+0

これを修正するにはどうすればよいですか? –

+0

@ElyadK比較する代わりにパスを割り当て、実際には 'path1'を呼び出します。 – Carcigenicate

0

いくつ

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: ") 

デフパス1()の例

この作品
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) 

ための独自のものでなければなりません。古いコードの問題は、パス1文、パスが値を持っていなかった場合は、

if path == 1: 

if path =='1': 

とパス1あなたが必要とする引数

関連する問題