Text-based adventure in Python 3 - python

I'm working on a text-based RPG, but I've found numerous problems, like:
being unable to go anywhere after entering the shop;
I cannot access the "tavern" for some reason; and
the computer just says "buy is not defined in crossbow".
Code:
gold = int(100)
inventory = ["sword", "armor", "potion"]
print("Welcome hero")
name = input("What is your name: ")
print("Hello", name,)
# role playing program
#
# spend 30 points on strenght, health, wisdom, dexterity
# player can spend and take points from any attribute
classic = {"Warrior",
"Archer",
"Mage",
"Healer"}
print("Choose your race from", classic,)
classicChoice = input("What class do you choose: ")
print("You are now a", classicChoice,)
# library contains attribute and points
attributes = {"strenght": int("0"),
"health": "0",
"wisdom": "0",
"dexterity": "0"}
pool = int(30)
choice = None
print("The Making of a Hero !!!")
print(attributes)
print("\nYou have", pool, "points to spend.")
while choice != "0":
# list of choices
print(
"""
Options:
0 - End
1 - Add points to an attribute
2 - remove points from an attribute
3 - Show attributes
"""
)
choice = input("Choose option: ")
if choice == "0":
print("\nYour hero stats are:")
print(attributes)
elif choice == "1":
print("\nADD POINTS TO AN ATTRIBUTE")
print("You have", pool, "points to spend.")
print(
"""
Choose an attribute:
strenght
health
wisdom
dexterity
"""
)
at_choice = input("Your choice: ")
if at_choice.lower() in attributes:
points = int(input("How many points do you want to assign: "))
if points <= pool:
pool -= points
result = int(attributes[at_choice]) + points
attributes[at_choice] = result
print("\nPoints have been added.")
else:
print("\nYou do not have that many points to spend")
else:
print("\nThat attribute does not exist.")
elif choice == "2":
print("\nREMOVE POINTS FROM AN ATTRIBUTE")
print("You have", pool, "points to spend.")
print(
"""
Choose an attribute:
strenght
health
wisdom
dexterity
"""
)
at_choice = input("Your choice: ")
if at_choice.lower() in attributes:
points = int(input("How many points do you want to remove: "))
if points <= int(attributes[at_choice]):
pool += points
result = int(attributes[at_choice]) - points
attributes[at_choice] = result
print("\nPoints have been removed.")
else:
print("\nThere are not that many points in that attribute")
else:
print("\nThat attribute does not exist.")
elif choice == "3":
print("\n", attributes)
print("Pool: ", pool)
else:
print(choice, "is not a valid option.")
print("Here is your inventory: ", inventory)
print("What do you wish to do?")
print("please input shop, tavern, forest.")
choice = input("Go to the shop, go to the tavern, go to the forest: ")
crossbow = int(50)
spell = int(35)
potion = int(35)
if choice == "shop":
print("Welcome to the shop!")
print("You have", gold,"gold")
buy = input("What would you like to buy? A crossbow, a spell or a potion: ")
if buy == "crossbow":
print("this costs 50 gold")
answer = input("Do you want it: ")
if answer == "yes":
print("Thank you for coming!")
inventory.append("crossbow")
gold = gold - crossbow
print("Your inventory is now:")
print(inventory)
print("Your gold store now is: ", gold)
if answer == "no":
print("Thank you for coming!")
if buy == "spell":
print("this costs 35 gold")
answear2 = input("Do you want it: ")
if answear2 == "yes":
print("Thank you for coming!")
inventory.append("spell")
gold = gold - spell
print("Your inventory is now:")
print(inventory)
if answear2 == "no":
print("Thank you for coming!")
if buy == "potion":
print("this costs 35 gold")
answear3 = input("Do you want it: ")
if answear3 == "yes":
print("Thank you for coming!")
inventory.append("spell")
gold = gold - potion
print("Your inventory is now:")
print(inventory)
if answear3 == "no":
print("Thank you for coming!")
choice = input("Go to the shop, go to the tavern, go to the forest: ")
while choice != "shop" or "tavern" or "forest":
print("Not acepted")
print("What do you wish to do?")
print("please input shop, tavern, forest.")
choice = input("Go to the shop, go to the tavern, go to the forest: ")
if choice == "teavern":
print("You enter the tavern and see a couple of drunken warriors singing, a landlord behind the bar and a dodgy figure sitting at the back of the tavern.")
tavernChoice = input("Would you like to talk to the 'drunken warriors', to the 'inn keeper', approach the 'dodgy figure' or 'exit'")
if tavernChoice == "drunken warriors":
print("You approach the warriors to greet them.")
print("They notice you as you get close and become weary of your presence.")
print("As you arrive at their table one of the warriors throughs a mug of ale at you.")
if dexterity >= 5:
print("You quickly dodge the mug and leave the warriors alone")
else:
print("You are caught off guard and take the mug to the face compleatly soaking you.")
print("The dodgy figure leaves the tavern")

The first time you ask the user where to go on line 111, what happens if they enter something besides "shop"? then the if choice == "shop": condition on line 119 will fail, and buy = input("...") will never execute. At that point, buy doesn't exist, so when the next conditional executes, it crashes because it can't evaluate if buy == "crossbow". buy has no value, so you can't compare it to anything.
You need to indent all of your shop logic so that it lies inside the if choice == "shop" block.
if choice == "shop":
print("Welcome to the shop!")
print("You have", gold,"gold")
buy = input("What would you like to buy? A crossbow, a spell or a potion: ")
if buy == "crossbow":
print("this costs 50 gold")
#...etc
if buy == "spell":
print("this costs 35 gold")
And the same problem is present for your tavern code. Even if you don't go to the tavern, you check for tavernChoice. That needs to be indented as well.
if choice == "teavern":
print("You enter the tavern and see a couple of drunken warriors singing, a landlord behind the bar and a dodgy figure sitting at the back of the tavern.")
tavernChoice = input("Would you like to talk to the 'drunken warriors', to the 'inn keeper', approach the 'dodgy figure' or 'exit'")
if tavernChoice == "drunken warriors":
print("You approach the warriors to greet them.")
At this point, your program will end, but I'm guessing you want to continue to be able to explore areas. You could put everything in a while loop, starting with the first input command.
while True:
print("Here is your inventory: ", inventory)
print("What do you wish to do?")
print("please input shop, tavern, forest.")
choice = input("Go to the shop, go to the tavern, go to the forest: ")
if choice == "shop":
print("Welcome to the shop!")
#...etc
elif choice == "tavern":
print("You enter the tavern...")
#...etc
elif choice == "forest":
print("You enter the forest...")
#etc
else:
print("Not acepted")
print("What do you wish to do?")
print("please input shop, tavern, forest.")
This is also a little cleaner than your current method, since you only have to ask the user where they're going once, instead of three times on lines 112, 165, and 170.

Building on Kevin's answer, here is a version with redundancy squeezed out, so you can add a new place just by adding a new def go_xyz(): ... near the top.
def go_shop():
print("Welcome to the shop!")
#...etc
def go_tavern():
print("You enter the tavern...")
#...etc
def go_forest():
print("You enter the forest...")
#etc
places = {name[3:]:globals()[name] for name in globals() if name.startswith('go_')}
placenames = ', '.join(places)
inventory = ['book']
retry = False
while True:
if not retry:
print("Here is your inventory: ", inventory)
else:
print("I do not know that place")
print("Where do you wish to go?")
print("Possible places: ", placenames, '.')
choice = input("? ")
try:
places[choice]()
retry = False
except KeyError:
retry = True

Related

How to make the program go back to the top of the code with a while loop?

I need to include a decrement life counter that has 5 lives. I need to use a while loop and once the player loses a life it needs to send them back to the choice between going left and right in the code. I am new to python so I am not very familiar with it, any help is appreciated.
answer = input("Do you want to go on an adventure? (Yes/No) ")
if answer.lower().strip() == "yes":
x=5
while x > 0:
print("You have ",x,"lives left.")
if x > 0:
break
x-=1
if x == 0:
break
answer= input("You are lost in the forest and the path splits. Do you go left or right? (Left/Right) ").lower().strip()
if answer == "left":
answer = input("An evil witch tries to cast a spell on you, do you run or attack? (Run/Attack) ").lower().strip()
if answer == "attack":
print("She turned you into a green one-legged chicken, you lost!")
elif answer == "run":
print("Wise choice, you made it away safely.")
answer = input("You see a car and a plane. Which would you like to take? (Car/Plane) ").lower().strip()
if answer == "plane":
print("Unfortunately, there is no pilot. You are stuck!")
elif answer == "car":
print("You found your way home. Congrats, you won!")
elif answer != "plane" or answer != "car":
print("You spent too much time deciding...")
else:
print("You are frozen and can't talk for 100 years...")
elif answer == "right":
import random
num = random.randint(1, 3)
answer = input("Pick a number from 1 to 3: ")
if answer == str(num):
print("I'm also thinking about {} ".format(num))
print("You woke up from this dream.")
elif answer != num:
print("You fall into deep sand and get swallowed up. You lost!")
else:
print("You can't run away...")
else:
print("That's too bad!")
You should try to add comments to your code, it will help you and others as well.
I think for getting user answer, you should use a different variable. It will make things easier.
I removed the following code, it didn't make any sense to me.
while x > 0:
print("You have ",x,"lives left.")
if x > 0:
break
x-=1
if x == 0:
break
--
This is the code, which works:
# Try to write imported modules at the top, it's a good practice.
import random
# Start the game
answer_start = input("Do you want to go on an adventure? (Yes/No) ")
# user chooses to play
if answer_start.lower().strip() == "yes":
lives=5
# function for displaying the lives
def display_lives():
print("You have ",lives,"lives")
#display lives
display_lives()
# As long lives are more than 0, this will keep going.
while lives>0:
#First choice
answer1= input("You are lost in the forest and the path splits. Do you go left or right? (Left/Right) ").lower().strip()
#User chooses left
if answer1 == "left":
answer2 = input("An evil witch tries to cast a spell on you, do you run or attack? (Run/Attack) ").lower().strip()
if answer2 == "attack":
print("She turned you into a green one-legged chicken, you lost!")
lives=lives-1
display_lives()
# User is running away
elif answer2 == "run":
print("Wise choice, you made it away safely.")
answer3 = input("You see a car and a plane. Which would you like to take? (Car/Plane) ").lower().strip()
if answer3 == "plane":
print("Unfortunately, there is no pilot. You are stuck!")
elif answer3 == "car":
print("You found your way home. Congrats, you won!")
elif answer3 != "plane" or answer3 != "car":
print("You spent too much time deciding...")
else:
print("You are frozen and can't talk for 100 years...")
elif answer1 == "right":
num = random.randint(1, 3)
answer4 = input("Pick a number from 1 to 3: ")
if answer4 == str(num):
print("I'm also thinking about {} ".format(num))
print("You woke up from this dream.")
elif answer4 != num:
print("You fall into deep sand and get swallowed up. You lost!")
lives=lives-1
else:
print("You can't run away...")
#Player chose not to play or player out of lives.
else:
print("That's too bad!")

Python Score Issues with Money in Negatives

I have game I'm making. Have a question. My current code is this:
import random
print("Welcome to Python Acey Ducey Card Game")
print()
print("Acey-ducey is played in the following manner: the dealer (computer) deals two cards faced up and you have an option to bet or not bet depending on whether or not you feel the card will have a value between the first two. If you do not want to bet, enter a $0 bet.")
bankbalance = 100
def main():
global bankbalance
print()
print("These cards are open on the table:")
print()
print("First card:")
firstcard = random.randint(1,13)
print(firstcard)
print("Second card:")
secondcard = random.randint(1,13)
print(secondcard)
playerinput = input("Enter your bet: ")
playerinput = int(playerinput)
dealercard = random.randint(1,13)
dealercard = int(dealercard)
print("The card you drew was", (dealercard), "!")
if dealercard > firstcard and dealercard < secondcard or dealercard < firstcard and dealercard > secondcard:
print("You win!")
bankbalance = bankbalance + playerinput
print("You currently have $", (bankbalance))
playagain = input("Would you like to play again y/n: ")
if playagain == ("y"):
main()
else:
exit
elif playerinput > (bankbalance):
print("You cannot bet more than you have!")
playagain = input("Would you like to play again y/n: ")
if playagain == ("y"):
main()
else:
exit
elif bankbalance == (0):
print("Oh no! You have no more money to bid.")
exit
else:
print("You lost!")
bankbalance = bankbalance - playerinput
print("You currently have $", (bankbalance))
playagain = input("Would you like to play again y/n: ")
if playagain == ("y"):
main()
else:
exit
main()
The problem is that you can have negative amount of money. How do I fix this? I've tried this:
elif bankbalance == (0):
print("Oh no! You have no more money to bid.")
exit
But that doesn't seem to work either. Any answers? I've tried to fix that issue, but my console doesn't follow it. It just says "You currently have $ 0".
You need to check if balance is equal to 0 whenever call your function. So, before proceeding any further, you need to add that if statement under global bankbalance:
import random
print("Welcome to Python Acey Ducey Card Game")
print()
print("Acey-ducey is played in the following manner: the dealer (computer) deals two cards faced up and you have an option to bet or not bet depending on whether or not you feel the card will have a value between the first two. If you do not want to bet, enter a $0 bet.")
bankbalance = 100
def main():
global bankbalance
if bankbalance == 0:
print("Oh no! You have no more money to bid.")
return
print()
print("These cards are open on the table:")
print()
print("First card:")
firstcard = random.randint(1,13)
print(firstcard)
print("Second card:")
secondcard = random.randint(1,13)
print(secondcard)
playerinput = input("Enter your bet: ")
playerinput = int(playerinput)
dealercard = random.randint(1,13)
dealercard = int(dealercard)
print("The card you drew was", (dealercard), "!")
if dealercard > firstcard and dealercard < secondcard or dealercard < firstcard and dealercard > secondcard:
print("You win!")
bankbalance = bankbalance + playerinput
print("You currently have $", (bankbalance))
playagain = input("Would you like to play again y/n: ")
if playagain == ("y"):
main()
else:
return
elif playerinput > (bankbalance):
print("You cannot bet more than you have!")
playagain = input("Would you like to play again y/n: ")
if playagain == ("y"):
main()
else:
return
else:
print("You lost!")
bankbalance = bankbalance - playerinput
print("You currently have $", (bankbalance))
playagain = input("Would you like to play again y/n: ")
if playagain == ("y"):
main()
else:
return
main()
Result when you reach 0 bank balance:
...
First card:
2
Second card:
2
Enter your bet: 100
The card you drew was 3 !
You lost!
You currently have $ 0
Would you like to play again y/n: y
Oh no! You have no more money to bid.
import random
print("\n\tWelcome to Python Acey Ducey Card Game\t\n")
print("Acey-ducey is played in the following manner: the dealer (computer) deals two cards faced up and you have an option to bet or not bet depending on whether or not you feel the card will have a value between the first two. If you do not want to bet, enter a $0 bet.")
bankbalance = 100
def main():
global bankbalance
print("\nThese cards are open on the table:\n")
print("First card:")
firstcard = random.randint(1,13)
print(firstcard)
print("Second card:")
secondcard = random.randint(1,13)
print(secondcard)
playerinput = int(input("Enter your bet: "))
if playerinput > (bankbalance):
print("You cannot bet more than you have!")
play_again()
dealercard = random.randint(1,13)
dealercard = int(dealercard)
print(f"The card you drew was {dealercard} !")
if dealercard > firstcard and dealercard < secondcard or dealercard < firstcard and dealercard > secondcard:
print("You win!")
bankbalance += playerinput
print(f"You currently have $ {bankbalance}")
play_again()
elif bankbalance <= 0:
print("Oh no! You have no more money to bid.")
exit()
else:
print("You lost!")
bankbalance -= playerinput
print(f"You currently have $ {bankbalance}")
play_again()
def play_again():
playagain = input("Would you like to play again y/n: ")
if playagain == ("y"):
main()
else:
exit()
main()
I rewrite your code a little bit.
import random
bank_balance = 100
play_again = True
def random_card() -> int:
return random.randint(1,13)
def set_bet():
try:
bet = int(input("Enter your bet: "))
except ValueError:
bet = 0
return bet
def play():
global bank_balance
print("These cards are open on the table:")
first_card = random_card()
second_card = random_card()
print(f"First card: {first_card}")
print(f"Second card: {second_card}")
bet = set_bet()
while (bet < 0) or (bet > bank_balance):
if bet > bank_balance:
print("You cannot bet more than you have!")
elif bet < 0:
print("You cannot bet <= 0 ")
bet = set_bet()
player_card = random_card()
print(f"The card you drew was {player_card}!")
if sorted([first_card, second_card, player_card])[1] == player_card:
bank_balance += bet
print('you win!')
else:
bank_balance -= bet
print('you lost!')
def main():
print("Welcome to Python Acey Ducey Card Game")
print()
print("Acey-ducey is played in the following manner: the dealer (computer)"
" deals two cards faced up and you have an option to bet or not bet"
" depending on whether or not you feel the card will have a value"
" between the first two. If you do not want to bet, enter a $0 bet.")
global play_again, bank_balance
while play_again:
print(f"You currently have $ {bank_balance}")
play()
if bank_balance <= 0:
print("Oh no! You have no more money to bid.")
play_again = False
else:
play_again = input("Would you like to play again y/n: ") == 'y'
main()

If else statement does not recognize the lists from input

I am learning how to make a text typed game in python. I could not get it to work. eventhough there is a water in my list (bag) it would still end the game eventhough i have it. Please help me
...
bag = [ ]
sword = ("sword")
water_bucket = ("water")
dead = False
ready = input("are you ready? ")
while dead == False:
print("this is whats inside your bag ")
print(bag)
if ready == "yes":
print("let's start our journey ")
print(
"It was a beautiful morning, you woke up in a dungeon, your quest is to find a dragon and slay his head off")
while dead == False:
if dead == True:
break
else:
first = input("Choose a path front/back/left/right")
if first == "front":
if bag == "water":
print(" You got safe because of the water bucket")
else:
dead = True
print(" You died in a hot lava")
elif first == "back":
ask2 = input("There is a sword, do you want to take it?")
if ask2 == "yes":
bag.append(sword)
print("You got a sword")
elif ask2 == "no":
print("you did not take it and went back to start")
else:
print("please answer with yes or no")
elif first == "left":
if bag == "sword":
print("You fought a dragon and win")
elif bag != "sword":
print("You fought a dragon but lost because you do not have a weapon")
dead = True
elif first == "right":
ask3 = input("Water Buckets! might be helpful, take it? ")
if ask3 == "yes":
bag.append(water_bucket)
print("You got a water bucket")
print(bag)
elif ask3 == "no":
print("you did not take it and went back to start")
else:
print("please answer with yes or no")
else:
print("not a path")
else:
print("See you next time, A journey awaits")
...
It is a text based im learning right now

Everything is leading to an else instead of it reading the input

The code:
import math
import time
import os
from random import *
def intro():
print("Welcome to battle. This is a game where you battle monsters.")
print("You will try to get the highest score you can.")
print("You start with 100HP. You will need to survive.")
print("You get a max revive every 10 battles.")
print("PS: This game is still in early alpha.")
print("Bugs are expected.")
game()
def game():
health = 100
revive = 0
print("You are greeted by a monster...")
print("1 = Fight")
print("2 = Take a chance at running")
choice = input("")
if choice == 1:
damage = randint(1,100)
health = health - damage
print("You killed the monster!")
print("But you took "+damage+" damage")
print("Your new health is: "+health)
if choice == 2:
print("You tried to run but failed.")
damage = randint(70,100)
health = health - damage
print("Your new health is: "+health)
else:
print("Wrong choice. You died.")
intro()
intro()
The problem: If you use 1 for choice it leads to else. Same with 2. Thanks to anyone that helps! PS: I am using Python 3. I don't know if that's important, I just need to fill out these lines.
Convert your input to int.
Ex:
choice = int(input())
and then replace
if choice == 2:
with
elif choice == 2:
Edit as per comments
def game():
health = 100
revive = 0
print("You are greeted by a monster...")
print("1 = Fight")
print("2 = Take a chance at running")
choice = int(input(""))
if choice == 1:
damage = randint(1,100)
health = health - damage
print("You killed the monster!")
print("But you took "+str(damage)+" damage") #-->Convert int to str before concatenation
print("Your new health is: "+str(health)) #-->Convert int to str before concatenation
elif choice == 2:
print("You tried to run but failed.")
damage = randint(70,100)
health = health - damage
print("Your new health is: "+str(health)) #-->Convert int to str before concatenation
else:
print("Wrong choice. You died.")
You firstly need to cast your input to an int by using int(input(""))
Then:
You need to use elif choice == 2: instead of if choice == 2:.

I am having a syntax error and i have no clue on what to do

I was writing a code in a programming book for beginners.
This is what it looks like. (I HAVE TO EXTEND THIS POST BECAUSE THIS WEBSITE IS SO FINICKY ABOUT QUESTION POSTS.)
import random
print("You are in a dark room in a mysterious castle.")
print("In front of you are four doors. You must choose one.")
playerChoice = input("Choose 1, 2, 3, or 4...")
if playerChoice == "1":
print("You found a room full of tresure. YOU'RE RICH!!!")
print("GAME OVER, YOU WIN!")
elif playerChoice == "2":
print("The door opens and an angry ogre hits you with his club.")
print("GAME OVER, YOU DIED!")
elif playerChoice == "3":
print("You encounter a sleeping dragon.")
print("You can do either:")
print("1) Try to steal some of the dragon's gold")
print("2) Sneak around the dragon to the exit")
dragonChoice = input("type 1 or 2...")
if dragonChoice == "1":
print("The dragon wakes up and eats you. You are delicious.")
print("GAME OVER, YOU WERE EATEN ALIVE.")
elif dragonChoice == "2":
print("You sneak around the dragon and escape the castle, blinking in the sunshine.")
print("GAME OVER, YOU ESCAPED THE CASTLE.")
else:
print("Sorry, you didn't enter 1 or 2.")
elif playerChoice == "4":
print("You enter a room with a sphinx.")
print("It asks you to guess what number it is thinking of, betwwen 1 to 10.")
number = int(input("What number do you choose?")
if number == random.randint (1, 10)
print("The sphinx hisses in dissapointment. You guessed correctly.")
print("It must let you go free.")
print("GAME OVER, YOU WIN.")
else:
print("The sphinx tells you that your guess is incorrect.")
print("You are now it's prisoner forever.")
print("GAME OVER, YOU LOSE.")
else:
print("sorry, you didn't enter 1, 2, 3, or 4...")
print("YOU TURN BACK AND LEAVE (YOU COWARD)")
Here are two of your problems:
number = int(input("What number do you choose?")
if number == random.randint (1, 10)
The cast to int is missing a closing parenthesis and the if statement is missing a colon.
The last problem has to do with the double else statement at the end. Un-indent the last one, assuming that is what you wanted.
Fixed:
import random
print("You are in a dark room in a mysterious castle.")
print("In front of you are four doors. You must choose one.")
playerChoice = input("Choose 1, 2, 3, or 4...")
if playerChoice == "1":
print("You found a room full of tresure. YOU'RE RICH!!!")
print("GAME OVER, YOU WIN!")
elif playerChoice == "2":
print("The door opens and an angry ogre hits you with his club.")
print("GAME OVER, YOU DIED!")
elif playerChoice == "3":
print("You encounter a sleeping dragon.")
print("You can do either:")
print("1) Try to steal some of the dragon's gold")
print("2) Sneak around the dragon to the exit")
dragonChoice = input("type 1 or 2...")
if dragonChoice == "1":
print("The dragon wakes up and eats you. You are delicious.")
print("GAME OVER, YOU WERE EATEN ALIVE.")
elif dragonChoice == "2":
print(
"You sneak around the dragon and escape the castle, blinking in the sunshine.")
print("GAME OVER, YOU ESCAPED THE CASTLE.")
else:
print("Sorry, you didn't enter 1 or 2.")
elif playerChoice == "4":
print("You enter a room with a sphinx.")
print("It asks you to guess what number it is thinking of, betwwen 1 to 10.")
number = int(input("What number do you choose?"))
if number == random.randint(1, 10):
print("The sphinx hisses in dissapointment. You guessed correctly.")
print("It must let you go free.")
print("GAME OVER, YOU WIN.")
else:
print("The sphinx tells you that your guess is incorrect.")
print("You are now it's prisoner forever.")
print("GAME OVER, YOU LOSE.")
else:
print("sorry, you didn't enter 1, 2, 3, or 4...")
print("YOU TURN BACK AND LEAVE (YOU COWARD)")
Python is a whitespace delimited language, which means you need to pay special attention to indentation. Your indentation is inconsistent which will inevitably lead to issues.
Other than that, you did not specify WHAT your error actually is. Add the syntax error information to your post.
You just had some problems with spacing and forgot ":" in line 30
import random
print("You are in a dark room in a mysterious castle.")
print("In front of you are four doors. You must choose one.")
playerChoice = input("Choose 1, 2, 3, or 4...")
if playerChoice == "1":
print("You found a room full of tresure. YOU'RE RICH!!!")
print("GAME OVER, YOU WIN!")
elif playerChoice == "2":
print("The door opens and an angry ogre hits you with his club.")
print("GAME OVER, YOU DIED!")
elif playerChoice == "3":
print("You encounter a sleeping dragon.")
print("You can do either:")
print("1) Try to steal some of the dragon's gold")
print("2) Sneak around the dragon to the exit")
dragonChoice = input("type 1 or 2...")
if dragonChoice == "1":
print("The dragon wakes up and eats you. You are delicious.")
print("GAME OVER, YOU WERE EATEN ALIVE.")
elif dragonChoice == "2":
print("You sneak around the dragon and escape the castle, blinking in the sunshine.")
print("GAME OVER, YOU ESCAPED THE CASTLE.")
else:
print("Sorry, you didn't enter 1 or 2.")
elif playerChoice == "4":
print("You enter a room with a sphinx.")
print("It asks you to guess what number it is thinking of, betwwen 1 to 10.")
number = int(input("What number do you choose?"))
if number == random.randint (1, 10):
print("The sphinx hisses in dissapointment. You guessed correctly.")
print("It must let you go free.")
print("GAME OVER, YOU WIN.")
else:
print("The sphinx tells you that your guess is incorrect.")
print("You are now it's prisoner forever.")
print("GAME OVER, YOU LOSE.")
else:
print("sorry, you didn't enter 1, 2, 3, or 4...")
print("YOU TURN BACK AND LEAVE (YOU COWARD)")

Categories

Resources