Cannot fix python invalid syntax - python

import time
print("hello, do you want to play this detective game?")
choice == input( "Yes or no?")
if choice 'no' :
print: "ok then, bye"
exit
if choice'yes':
start
name == input("Enter your name")
print("hello, " + name ", in this game you are a famous detective handling a theft case."
time.sleep(1)
print(" you have gone on a holiday but ended up lost in the forest. you see a man walking up to you")
time.sleep(1)
print ("man:' hi there! you seem quite lost! Do you want to stay the night with me?'")
print(" you said:'why should i? i dont even know you'")
print(" man : ' Do as you please, but if you stay in the forest for the night here's a friendly warning: there's wild wolves in the forests.'")
choose == input( "stay the night or refuse?" )
if choose "refuse":
print("man: ' boy, you are stubborn!")
print( "the man walks away, leaving you behind" + " In the end, you got eaten by the wolves due to your stubborness. THE END")
choice == input("do you want to play again? yes or no?")
if choice "yes":
start
if choice "no":
print( "ok then, bye!")
exit
Basically my question is this ' invalid syntax' at the upper [do you want to play? ] 'no' response.
But when I erase it the problem goes to the next line. It is very annoying and i cant find how to solve it.
I tried changing between ' and " but the result is still the same.
I would be glad if any of you would take the time to response as i just started yesterday and is still not very clear about invalid syntax.

if choice 'no' :
is the culprit (and same problem on line 8 and elsewhere). The expression requires a == to make:
if choice == 'no' :
However, line 3 will cause a problem before you get there - choice is not defined. == is a logical operator, it does not mean assignment as the code would seem to need to do at that point. Change it to perform assignment with =:
choice = input( "Yes or no?")
Also, it's better to test against lower case because you don't know what combination of upper and lower case characters might be entered by the user:
if choice.lower() == 'no' :
Line 9 reads start - again. Perhaps you mean that as a comment? If so add a '#' at the start of the line.
These problems are the tip of the iceberg. Perhaps you should read a few tutorials and code in small iterative increments to build up your program.

issues:
choice == input() is wrong make it choice = input()
choice 'no' : is again in many place wrong make it choice == 'no'
start/exit is not required
print() function must have closing parenthesis
fixed code:
import time
def my_game():
print("hello, do you want to play this detective game?")
choice = input( "Yes or no?")
if choice == 'no' :
print("ok then, bye")
if choice == 'yes':
name = input("Enter your name")
print("hello, " + name + ", in this game you are a famous detective handling a theft case.")
time.sleep(1)
print(" you have gone on a holiday but ended up lost in the forest. you see a man walking up to you")
time.sleep(1)
print ("man:' hi there! you seem quite lost! Do you want to stay the night with me?'")
print(" you said:'why should i? i dont even know you'")
print(" man : ' Do as you please, but if you stay in the forest for the night here's a friendly warning: there's wild wolves in the forests.'")
choose = input( "stay the night or refuse?" )
if choose == "refuse":
print("man: ' boy, you are stubborn!")
print( "the man walks away, leaving you behind" + " In the end, you got eaten by the wolves due to your stubborness. THE END")
choice = input("do you want to play again? yes or no?")
if choice == "yes":
my_game()
if choice == "no":
print( "ok then, bye!")
if __name__ == "__main__":
my_game()

Try this:
import time
def game()
print("hello, do you want to play this detective game?")
choice == input( "Yes or no?")
if choice == 'no' :
print("ok then, bye")
break
if choice == 'yes':
name == input("Enter your name")
print("hello, " + name ", in this game you are a famous detective handling a theft case."
time.sleep(1)
print(" you have gone on a holiday but ended up lost in the forest. you see a man walking up to you")
time.sleep(1)
print ("man:' hi there! you seem quite lost! Do you want to stay the night with me?'")
print(" you said:'why should i? i dont even know you'")
print(" man : ' Do as you please, but if you stay in the forest for the night here's a friendly warning: there's wild wolves in the forests.'")
choose == input( "stay the night or refuse?" )
if choose == "refuse":
print("man: ' boy, you are stubborn!")
print( "the man walks away, leaving you behind" + " In the end, you got eaten by the wolves due to your stubborness. THE END")
choice == input("do you want to play again? yes or no?")
if choice == "yes":
game()
if choice == "no":
print("ok then, bye!")
break
else:
#continue your game here
Hope this works! This might be better.

Related

Last run code is having problems with starting the code because indented block

Im having problem with the last code- "intro()" its stopping me from running the code so if anyone would be able to figure out whats wrong it would be of big help
*
I believe its not working because of a typo somewhere but iam unable to locate it or fix it so i hope any of yall can spot it and help me out?
it asks me to add more detail but there isnt much more i can say :/
import time
from termcolor import colored, cprint
answer_A = ["A", "a"]
answer_B = ["B", "b"]
answer_C = ["C", "c"]
yes = ["Y", "y", "yes"]
no = ["N", "n", "no"]
phone = 1
Lady_name = 0
Lady_lastname = 0
required = ("\nUse only A, B, or C\n")
print("=========================================================")
def Intro():
print ("\n\n You are sitting at the bar like every friday... ")
time.sleep(2)
print ("\n After your wife passed away, you don't really know what to do anymore")
time.sleep(2)
print ("\n You see a lady looking at you in the cornor of your eye.")
time.sleep(2)
print("""\n A. Move over and talk to the lady .
B. Let the lady be, she probably thinks you are weird.""")
choice = input(">>> ")
if choice in answer_A:
time.sleep(1)
option_lady()
elif choice in answer_B:
print("\n You let the lady be... \n You have been sitting here a while now and the lady have been glancing over at me the whole time.")
time.sleep(3)
print ("\n You glance over at her wondering if she is watching you.")
time.sleep(2)
print ("\n You make eye contact")
time.sleep(1)
print("""\n A. Go and talk to the lady.
B. Go home for the night.""")
choice = input(">>> ")
if choice in answer_A:
option_lady()
elif choice in answer_B:
print("\n You go and home and the lady looks sad. \n\n You go to sleep and never wake up again...")
def option_lady():
print ("\n you walk over to the lady")
print("""\n A. Hey, how you doing?
B. Hey, whats your name?""")
choice = input(">>> ")
if choice in answer_A:
option_question
elif choice in answer_B:
Lady_name = 1
Lady_lastname = 1
print ("\n Hey, Whats your name? You say.")
time.sleep(1)
cprint ('\nTracey! My name is Tracey smith.', 'red')
time.sleep(1)
Lady_name = 1
Lady_lastname = 1
print("\nWhat are you gonna answer? ")
print("""\n A. How are you doing?
\nB. Can I buy you a drink?""")
choice = input (">>> ")
if choice in answer_A:
print("dsa")
elif choice in answer_B:
Intro()
'
Your code ends in elif choice in answer_B:. Any statement ending in : must have a body, some code. If you explicitly don't want to put anything there, python provides pass exactly for that reason.:
elif choice in answer_B:
pass
should fix it.

I keep getting a NameError in Python, saying that things are not defined, although I did define them

So I'm creating this based of this resource, linked here: https://www.derekshidler.com/how-to-create-a-text-based-adventure-and-quiz-game-in-python/
EDIT: Here is a GitHub link to all the code: https://github.com/gabby-lucies/Quarter-1-Project/blob/master/intro.py
I'm currently stuck however, in my very first option, anytime to choose any of the options listed below, I get a NameError saying that my options are not defined. Can anyone give me any advice? Thanks! Also, sorry if this is a dumb question.
#importing
import time
#How players could respond
answer_A = ["A", "a"]
answer_B = ["B", "b"]
answer_C = ["C", "c"]
yes = ["Y", "y", "yes"]
no = ["N", "n", "no"]
#Objects
fwomp = 0
bownarrow = 0
sword = 0
money = 0
#playerName = input("Enter Your Name: ") #gets the player's name, obviously
required = ("\nUse only A, B, or C.\n")
#Startup
def intro():
#print("There is no saving. Sorry!")
#print("Hello! Please enter your name.")
#print("Nice to meet you!")
print("Let's begin!")
print("You wake up in a forest. You can't remember anything. You look around and find")
print("a small creek. You hear sound nearby that sounds like some sort of woodland creature.")
print("You also see some smoke in the distance. What would you like to do ?")
time.sleep(2)
#Choice 1 Options
print("A. Follow the creek.")
print("B. Follow the sound of the woodland creature.")
print("C. Walk towards the smoke.")
choice = input(">>> ") #gets choice
time.sleep(1.5)
if choice in answer_A:
option_creek() #Gives player creek option
elif choice in answer_B:
option_animal() #Give Fwomp options
elif choice in answer_C:
option_smoke() #Gives smoke options
else:
print(required)
intro()
def option_creek():
print("You follow the creek for an hour, and you eventually come across the river.")
print("You followed the river for another hour, and you found a riverside village.")
print("You walk into the village, desperately looking for food and water.")
print("You come across a large pub. It doesn't look very busy.")
print("You also come across an elegant resturant. It must be very expensive.")
print("There is also family outside of their house eating freshly picked food from their garden.")
print("Where will you go?")
print("A. Pub B. Resturant C. Family")
time.sleep(2.5)
choice = input(">>> ")
if choice in answer_A:
option_pub()
if choice in answer_B:
option_resturant()
if choice in answer_C:
option_family()
else:
print(required)
option_creek()
def option_smoke():
print("You walk towards the smoke. Eventually you find the source of the smoke.")
print("The smoke is coming from a lost and very angry tribe.")
print("They also don't speak your language.")
print("When they spot you, and you have nothing to offer them in return, so they assume you are there to kill them.")
print("Anways, fifty of them shot you with arrows all at once.")
time.sleep(2)
print("Also, you're dead!")
time.sleep(2)
option_smoke()
def option_animal():
print("Seriously, you walked towards a strange animal sound just like that?")
print("Luckily, it is only a Fwomp. It doesn't kill you, but it does glare at you strangely.")
print("Fwomps are cute, so you want to pet it.")
print("You also want to take the Fwomp.")
print("You're also hungry and horrible so you also kind of want to eat the Fwomp.")
print("What will you do?")
print("A. Pet Fwomp B. Take Fwomp C. Eat Fwomp")
time.sleep(2.5)
choice = input(">>> ")
if choice in answer_A:
fwomp = 1
option_petfwomp()
elif choice in answer_B:
fwomp = 1
option_takefwomp()
elif choice in answer_C:
option_eatfwomp()
else:
print(required)
option_animal()
I've looked over your github code, so i'm changing my answer for that
After each of your option functions, you're immediately calling it, shown here
def option_animal():
print("Seriously, you walked towards a strange animal sound just like that?")
print("Luckily, it is only a Fwomp. It doesn't kill you, but it does glare at you strangely.")
print("Fwomps are cute, so you want to pet it.")
print("You also want to take the Fwomp.")
print("You're also hungry and horrible so you also kind of want to eat the Fwomp.")
print("What will you do?")
print("A. Pet Fwomp B. Take Fwomp C. Eat Fwomp")
time.sleep(2.5)
choice = input(">>> ")
if choice in answer_A:
fwomp = 1
option_petfwomp()
elif choice in answer_B:
fwomp = 1
option_takefwomp()
elif choice in answer_C:
option_eatfwomp()
else:
print(required)
option_animal()
As python is a procedural language, only the code that is before this call in the file exists, thus, at the point where you call option_animal, option_petfwomp doesn't exist, however if you remove all of these function calls and move them to the end of the file, it should work.
Hope this helps
Your code is not wrong, it's simply incomplete. I'm assuming you're using this to learn Python. Let me ask you a quick question. When you press run, you get some options.
What will you do?
A. Pet Fwomp B. Take Fwomp C. Eat Fwomp
If I type "A" and hit enter, it runs option_petfwomp()
But in your code you haven't defined this function.
If you add:
def option_petfwomp():
print("option_petfwomp")
def option_takefwomp():
print("option_takefwomp")
def option_eatfwomp():
print("option_eatfwomp")
you'll understand how it works. Basically, you are controlling the flow of the program. If you define these functions, you can then call them from your game.
My advise:
Think about what you want your code to do.
Map it out as a diagram or psuedo-code.
Code it.
It seems like you copy-pasted the code, without knowing what it does, or knowing what you want it to do. That's all fine, but take time out to understand your code before hoping someone else will understand it for you.

Why is my code not following the if/else statement and instead jumping to a different place?

I have to make a text based adventure game for a school project. I'm stuck at the point where the user is asked to 'Enter 1 to hide, Enter 2 to confront Jacob.'
Instead of the code doing what I expect it to do, if the user enters '1' then it prints 'jacob pulls out a gun and shoots you...'
what I want is for it to print the line 'You hide behind some firewood...'
I know my code is quite messy, I'm really sorry.
Does anyone know what I've done wrong here?
enter = input("Do you enter the cabin? >")
if enter == 'Yes' or enter == 'yes' or enter == 'Y' or enter == 'y':
print("you decide to enter the cabin. There's someone in there. You recognise their face from the ID card you found earlier. It's Jacob Adams.")
print("JACOB:", name_f+',',"what are you doing here. You're alive?")
response = input("Enter 1 for 'Yes, I'm alive. I'm guessing that's no thanks to you!' Enter 2 for 'What are you talking about? Who are you? What the hell is going on?'")
if response == '1':
print("JACOB: This is nothing personal,", name_f)
elif response == '2':
print("JACOB: Don't worry,", name_f+',',"It'll all make sense soon enough")
print("Jacob pulls out a gun and shoots you in the head before you have a chance to respond.")
print("GAME OVER")
if enter == 'No' or enter == 'no' or enter == 'N' or enter == 'n':
print("You decide to stay on the safe side. You creep around the back of the cabin and peer in through the window. You can't believe your eyes")
print("There's someone in there. You recognise their face from the ID card you found earlier. It's Jacob Adams")
print("He seems to be on the phone with someone")
spy = input("Do you a)listen to the conversation or b)walk away before he sees you")
if spy == 'a' or spy == 'A' or spy == 'listen' or spy == 'Listen' or spy == 'listen to the conversation' or spy == 'Listen to the conversation':
print("JACOB: Yes I took care of it. I'm pretty sure", pronoun+"'s", "dead.")
print('JACOB: I left', pronoun_2, 'in the middle of nowhere. Even if', pronoun, 'somehow survived,', pronoun, "won't have lasted five minutes where I left", pronoun_2)
print('JACOB:',pronoun+"'s", 'probably under a foot of snow by now')
print('JACOB:...')
print('JACOB:...')
print('JACOB:...')
print('JACOB: Damnit!', pronoun.title(), "still has my diary. We can't have someone find that with the body. I should go back and get it")
print("Jacob gets up and heads towards the door.")
hide = input("Enter 1 to hide. Enter 2 to confront Jacob")
if hide == 1:
print("you hide behind some firewood. He doesn't see you.")
print("Now's your chance:")
diary = input("Do you a)read Jacob's diary or b)enter the cabin")
if diary == "read Jacob's diary" or diary == "Read Jacob's diary" or diary == "read jacob's diary" or diary == "Read jacob's diary" or diary == 'a' or diary == 'A' or diary == 'Read diary' or diary == 'read diary' or diary == 'Diary' or diary == 'diary':
code = input("Enter a four digit code")
if code == '1302':
print("You unlocked the diary")
print("As you read the diary, your memories come back to you. Jacob, your business partner, and", spouse_name, "had been conspiring to kill you for the last two years. Once you died", spouse_name, "was supposed to receive your three million dollar inheritance.")
print(spouse_name, "had promised to split the money with Jacob in return for murdering you and disposing of your body. Luckily, a few months ago you found Jacob's bag lying around. You were suspicious that he was trying to cheat you out of your business, and decided to snoop")
print("You found his diary, and instantly knew that the code would be 1302, the date that you and Jacob founded your startup. When you learnt of", spouse_name, "Jacob's plot, you grabbed the bag and went into hiding. Unfortunately Jacob eventually found you, knocked you out cold and left you for dead in the middle of nowhere.")
print("You learn that the cabin belong's to Jacob's late grandfather. Jacob keeps a handgun in the sidetable drawer and a knife in the sofa cushion.")
print("You need to call the police!")
final = input("Enter 1 to enter the Cabin and look for supplies or Enter 2 to shout for help. >")
if final == '1':
print("You enter the cabin. You see a fireplace, some food and a telephone")
choice = input ("What do you do now? >")
print("Jacob had forgotten something back at the cabin. He comes back in to retreive it. You've been spotted.")
print("JACOB:", name_f+',',"what are you doing here. You're alive?")
response = input("Enter 1 for 'Yes, I'm alive. I'm guessing that's no thanks to you!' Enter 2 for 'What are you talking about? Who are you? What the hell is going on?'")
if response == '1':
print("JACOB: This is nothing personal,", name_f)
elif response == '2':
print("JACOB: Don't worry,", name_f+',',"It'll all make sense soon enough")
print("You know that Jacob is dangerous. You recall the gun and the knife that Jacob keeps in his cabin")
weapon = input("Enter 1 to go for the gun or Enter 2 to go for the knife >")
if weapon == '1':
print("you run to the sidetable to look for the handgun but when you open the drawer it's empty")
print("Jacob pulls out a gun and shoots you in the head")
print("GAME OVER")
elif weapon == '2':
print("You run to the sofa cushion and pull out a knife")
print("As you threaten Jacob with your knife, he pulls out a handgun and holds it up to your head")
print("you notice a bright ray of light shining in through the window and use your knife to reflect it back into Jacob's eyes.")
print("While he is still stunned by the light, you take the opportunity to grab his gun and shoot him in the leg")
print("You run to the telephone and call the police")
print("CONGRATULATIONS!")
elif final == '2':
print("Oh dear, it looks like Jacob heard you...")
print("JACOB:", name_f+',',"what are you doing here. You're alive?")
response = input("Enter 1 for 'Yes, I'm alive. I'm guessing that's no thanks to you!' Enter 2 for 'What are you talking about? Who are you? What the hell is going on?'")
if response == '1':
print("JACOB: This is nothing personal,", name_f)
elif response == '2':
print("JACOB: Don't worry,", name_f+',',"It'll all make sense soon enough")
print("Jacob pulls out a gun and shoots you in the head before you have a chance to respond.")
print("GAME OVER")
else:
print("you only had one chance to enter the code. The diary is locked forever. You walk into the cabin to look for clues instead.")
print("Jacob forgot something in the cabin and comes back in to retreive it. You've been spotted.")
print("JACOB:", name_f+',',"what are you doing here. You're alive?")
response = input("Enter 1 for 'Yes, I'm alive. I'm guessing that's no thanks to you!' Enter 2 for 'What are you talking about? Who are you? What the hell is going on?'")
if response == '1':
print("JACOB: This is nothing personal,", name_f)
elif response == '2':
print("JACOB: Don't worry,", name_f+',',"It'll all make sense soon enough")
print("Jacob pulls out a gun and shoots you in the head before you have a chance to respond.")
print("GAME OVER")
elif diary == 'enter the cabin' or diary == 'b' or diary == 'B' or diary == 'Enter the cabin' or diary == 'Enter cabin' or diary == 'enter cabin':
print("Jacob forgot something in the cabin and comes back in to retreive it. You've been spotted.")
print("JACOB:", name_f+',',"what are you doing here. You're alive?")
response = input("Enter 1 for 'Yes, I'm alive. I'm guessing that's no thanks to you!' Enter 2 for 'What are you talking about? Who are you? What the hell is going on?'")
if response == '1':
print("JACOB: This is nothing personal,", name_f)
elif response == '2':
print("JACOB: Don't worry,", name_f+',',"It'll all make sense soon enough")
print("Jacob pulls out a gun and shoots you in the head before you have a chance to respond.")
print("GAME OVER")
elif hide == 2:
print("JACOB:", name_f+',',"what are you doing here. You're alive?")
response = input("Enter 1 for 'Yes, I'm alive. I'm guessing that's no thanks to you!' Enter 2 for 'What are you talking about? Who are you? What the hell is going on?'")
if response == '1':
print("JACOB: This is nothing personal,", name_f)
elif response == '2':
print("JACOB: Don't worry,", name_f+',',"It'll all make sense soon enough")
print("Jacob pulls out a gun and shoots you in the head before you have a chance to respond.")
print("GAME OVER")
input() gives you a string - you compare it to an integer:
hide = input("Enter 1 to hide. Enter 2 to confront Jacob")
if hide == 1:
A string is never equal to an integer, change it to:
hide = input("Enter 1 to hide. Enter 2 to confront Jacob")
if hide == "1":
or convert to int (will crash if non-int text is inputted):
hide = int( input("Enter 1 to hide. Enter 2 to confront Jacob"))
if hide == 1:
You posted much more code then needed - it would have been enough to post:
hide = input("Enter 1 to hide. Enter 2 to confront Jacob")
if hide == 1:
# do smth
pass
elif hide == 2:
# do smth other
pass
To avoid having to compare so many options you can lower() the input and compare against a list of things:
spy = input("Do you a)listen to the conversation or b)walk away before he sees you")
if spy == 'a' or spy == 'A' or spy == 'listen' or spy == 'Listen' or spy == 'listen to the conversation' or spy == 'Listen to the conversation':
is shorter if you do:
spy = input("Do you a)listen to the conversation or b)walk away before he sees you").lower()
# you could use a set - but python will inline this as frozenset anyhow
if spy in ('a' ,'listen','listen to the conversation'):
You might want to read through How to debug small programs to pick up some debugging tips.

Python programming, syntax error for game

#makes a varible called name to identify the players name
name=input("Hello person, Whats your name?")
#prints their name
print("Hello", name)
#console asks the player if they want to play the game, if choice is "yes" then continue, else say "ok bye bye" (at the bottom!!)
print("Do you want to hear a story?", name)
choice=input("Yes, No?")
if choice==("yes" or "yes " or "Yes" or "Yes "):
print("Ok", name,", listen up")
print("There was once an old, old house at the top of a hill Sooooo high it was above the clouds")
housename=input("What do you want to call the house?")
print("The old,",housename,"was once owned by an old lady. You decide to go up to the", housename, ",you encounter a ghost in your path. You see a varitety of weapons beside you, an axe, sword and a bow.")
#asks the player if they want an axe sword or bow
choice3=input("Do you choose the axe, sword or bow?")
#if the choice is "bow" then proceed with this code
if choice3==("bow" or "Bow" or "bow " or "Bow "):
print("You equip the shoddy Bow, The bow feels as if it could snap any second.")
#sets the enemyshealth as 10
enemyhealth=int(10)
#makes a while loop to keep the battle going instead of 1 time.
while enemyhealth >= 1:
print("Take a shot!")
bowattack=input("Type attack to fire an arrow!")
if bowattack==("attack"):
import random
#randomiser for damage generator
damage = ["1", "2", "3", "4"]
damage2 = int(random.choice(damage))
enemyhealth = enemyhealth - damage2
print("The ghost took some damage. Enemys health:", enemyhealth)
else:
print("Are you sure you typed shoot?")
#if the enemys health gets below 1 print you killed the ghost, reward system! **this is what im having trouble with!!**
if enemyhealth <= 1:
print("You killed the Ghost!!")
print("You vanquished the ghost, you now collect a new weapon!")
#confirms the reward, either gives the player a shiny bow or a double shot bow.
import random
reward = ["Shiny bow", "Doubleshot bow"]
#randomiser for either reward
reward2 =(random.choice(reward)
#prints what weapon the player got
#THIS IS THE PROBLEM, ON THIS LINE
print("You got a:", reward2)
#pointless easteregg :D
elif choice==("maybe"):
print("You found an easter egg, congrats. PS this does nothing")
#if the player typed anything other than yes say ok bye bye.
else:
print("Ok, bye bye", name)
I am fully aware that the code does not yet have the other 2 if statements for the axe or sword. What i'm having trouble with is the reward generator for killing the ghost. I think its an indention error; it says syntax error for the print line.
I know this is rather alot of code to take in but i'd really appreciate it if could help me fix this; if you see anything I could make a shortcut around that would also be helpful.
Im using python 3.4.2!
You're missing a closing parenthesis in the previous line:
reward2 =(random.choice(reward)
should be:
reward2 =(random.choice(reward))
Also, the line if choice==('yes' or 'yes ' or 'Yes' or 'Yes '): wont work.
Try this:
if choice.strip().lower() == 'yes':
# whatever
strip will remove whitespaces. lower will put the string in lowercase
The same happens with choice3

How do I move to different parts of code in this game/story

After the initial question of how much do you take, it works fine. If you type 0 you die, 5 million it says nice take. After it says nice take, it exits the program and forgets the rest of the code.
How do I get python to load the next part of the code and run it.
from sys import exit
def bank_vault():
print "This room is full of money up to 5 million dollars. How much do you take?"
choice = raw_input("> ")
if "0" in choice:
dead("You are robbing a bank and took nothing... The cops shot you in the face.")
how_much = int(choice)
if how_much < 5000000:
print "Nice take, now you have to escape!"
escape_route()
def escape_route():
print "There are cops blocking the front door."
print "There are cops blocking the back door."
print "There is no way to get out of there."
print "You see a small opening on the ceiling."
print "Type ceiling to go through it."
print "Or type stay to try your luck."
escaped_cops = False
while True:
choice = raw_input("> ")
if choice == "stay":
dead("Your bank robbing friends left your stupid ass and the cops shot you in the face. Idiot move dipshit.")
elif choice == "ceiling" and not escaped_cops:
print "You escaped! Now wash that money and don't go to prison."
escaped_cops = True
def dead(why):
print why, ""
exit(0)
bank_vault()
Cool game. I love games and would like to try to improve your code. Code below works on Python 3. It should work on Python 2:
from sys import exit
try: input = raw_input # To make it work both in Python 2 and 3
except NameError: pass
def bank_vault():
print("This room is full of money up to 5 million dollars. How much do you take?")
how_much = int(input("> ")) # Why not eliminate choice variable here?
if how_much == 0:
dead("You are robbing a bank and took nothing... The cops shot you in the face.")
elif how_much < 5000000: # Changed to else condition
print("Nice take, now you have to escape!")
else: # Added a check
dead("There isn't that much!")
def escape_route():
print("There are cops blocking the front door.")
print("There are cops blocking the back door.")
print("There is no way to get out of there.")
print("You see a small opening on the ceiling.")
print("Type ceiling to go through it.")
print("Or type stay to try your luck.")
escaped_cops = False
while not escaped_cops:
choice = input("> ")
if choice == "stay":
dead("Your bank robbing friends left your stupid ass and the cops shot you in the face. Idiot move dipshit.")
elif choice == "ceiling":
print("You escaped! Now wash that money and don't go to prison.")
escaped_cops = True
def dead(why):
print(why)
exit(0)
bank_vault()
escape_route()
You have to call the function escape_route rather than exit.
Also, when checking for choice you call dead no matter what.
In reply to your comment:
You need to check if it's 0 then call dead, if it's not 0 don't bother with the else, go directly to the if how_much < 5000000 and call escape_route
You need to try and convert the input to an int if it isn't 0!
And what happens if they take more than 5 mil?

Categories