0

I'm new to python and this is my first real program. Heres the code:

def home():
    print ('game....play-1..options-2..rules-3..exit-4..')
    answer = input()
    print(repr(answer))
    if answer == '1':
        play()
    elif answer == '2':
        options()
    elif answer == '3':
        rules()
    elif answer == '4':
        end()


def rules():
    print ('rules...main menu-1...exit-2..')
    answerRules = input ()
    print(repr(answerRules))    
    if answerRules == '1':
        home()
    elif answerRules == '2':
        end()

home()

The main problem i get here is that it works fine in the python shell but not with command prompt. In command prompt home() works however once you enter an answer, e.g. 3. the program just ends.

4

2 に答える 2

1

答えはタイプですint

で確認しif answer == 1:
て解決します

于 2012-11-10T18:22:52.043 に答える
0

コマンド プロンプトから実行したときに、input() が改行またはその他の文字を返しているかどうかを確認する必要があります。

于 2012-11-10T18:22:41.753 に答える