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.

3
  • What version of python? If 2.x, input will return an int, not a string Commented Nov 10, 2012 at 18:21
  • I think that you should mention the operating system you use. Commented Nov 10, 2012 at 18:22
  • 2
    Works on my system. Win7_64 + python 3.0.1 (2 bit). Please mention your OS & python version. Commented Nov 10, 2012 at 18:26

2 Answers 2

1

answer is type of int

so check with if answer == 1:
It will resolve

Sign up to request clarification or add additional context in comments.

2 Comments

I think the print() function suggests that the OP is on python3.x, so input() is not an int in that case.
@OliverBennett you're on python 2.x?
0

You should check to see if input() is returning the carriage return or some other character when you run it from the command prompt.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.