2

So I have this game:

import sys

def Start():
    print("Hello and welcome to my first Python game. I made it for fun and because I am pretty bored right now.")
    print("I hope you enjoy my EPIC TEXT GAME")

play = input("do you want to play? (Y / N) ")

if play == "Y":
    game()

if play == "N":
    sys.exit()

def game():
    print("That's pretty much what I've done so far! :P -- yea yea, it's nothing -- IT IS!. Bye now")
    input("Press enter to exit")

If I type "Y" I want to go to game(). It doesn't.

interjay
  • 107,303
  • 21
  • 270
  • 254
user2261574
  • 91
  • 1
  • 1
  • 3

2 Answers2

4

You have defined game after you tried and use it. You need to define functions, variables, etc. before you use them. Also, your code only matched on upper case Y and not lower case y. To make all input upper case, you should use the .upper() method on it
Change the code to:

def game():
    print("That's pretty much what I've done so far!")
    input("Press enter to exit")

if play.upper() == "Y":
    game()
elif play.upper() == "N":
    sys.exit()

It is usually best form to not have any global code, and instead include it in a main function if the python code is being run as the main. You can do this by using:

if __name__ == "__main__":
    Start()

And then put all that global code into the Start method. Again, make sure you declare before you use.

Salvatore
  • 10,815
  • 4
  • 31
  • 69
Serdalis
  • 10,296
  • 2
  • 38
  • 58
  • No problem. you should consider looking at [Learn Python The Hard Way](http://learnpythonthehardway.org/book/) to get all this juicy knowledge. – Serdalis Apr 09 '13 at 12:11
0

You're using the input() function which executes the input as a command immediately after reading it from stdin.

You probably want to use raw_input() which will simply return what the user entered

BradS
  • 1,935
  • 1
  • 13
  • 13
  • This is python 3.0 which does not have `raw_input` (you can tell by the print statement). – Serdalis Apr 09 '13 at 12:14
  • The print function is valid in Python 2.7 as well. I didn't know about the input/raw_input change in 3.x. Thanks. – BradS Apr 10 '13 at 00:51