I keep getting error messages for the bold part but i dont know how to fix it

import random
from random import choice
import time
from time import sleep
def print_pause(message_to_print):
print(message_to_print)
time.sleep(2)

#dragon’s house

def dragon_house():
print_pause(“You approach the door of the house.”)
print_pause(“You are about to knock when the door opens and” “out steps a dragon.”)
print_pause(“Eep! This is the dragon’s house!”)
print_pause(“The dragon finds you!”)
print_pause(“You feel a bit under-prepared for this,” “what with only having a tiny,” “rusty old magic wand.”)

#troll house
def troll_house():
print_pause(“You approach the door of the house.”)
print_pause(“You are about to knock when the door opens and” “out steps a troll.”)
print_pause(“Eep! This is the troll’s house!”)
print_pause(“The troll finds you!”)
print_pause(“You feel a bit under-prepared for this,” “what with only having a tiny,” “rusty old magic wand.”)
#pirate’shouse
def pirate_house():
print_pause(“You approach the door of the house.”)
print_pause(“You are about to knock when the door opens and” “out steps a pirate.”)
print_pause(“Eep! This is the pirate’s house!”)
print_pause(“The dpirate finds you!”)
print_pause(“You feel a bit under-prepared for this,” “what with only having a tiny,” “rusty old magic wand.”)
#witch’s house
def witch_house():
print_pause(“You approach the door of the house.”)
print_pause(“You are about to knock when the door opens and a witch” “out steps.”)
print_pause(“Eep! This is the witch’s house!”)
print_pause(“The dragon finds you!”)
print_pause(“You feel a bit under-prepared for this,” “what with only having a tiny,” “rusty old magic wand.”)

houses = [ witch_house, troll_house, dragon_house, pirate_house]

def cave():
print_pause(“You peer cautiously into the cave.”)
print_pause(“It turns out to be only a very small cave.”)
print_pause(“Your eye catches a glint of metal behind a rock.”)
print_pause(“you have found the magical Wand of Ogoroth!”)
print_pause(“You discard your rusty old magic wand and take the Wand of Ogoroth with you.”)
print_pause(“You walk back out to the field.”)

print_pause(“You find yourself standing in an open field, filled with grass and yellow wildflowers.”)

print_pause(" Rumor has it that a wicked fairy is somewhere around here and has been terrifying the nearby village.")

print_pause(“In front of you is a house.”)

print_pause(“To your right is a dark cave.”)

print_pause(“In your hand you hold your trusty (but not very effective magic wand.”)

x= input()
if x == 1:
** print(random.choice(houses)**
elif x > 1 < 3:
** print(cave)**
else:
** print(“please enter 1 or 2”)**

print_pause(“Enter 1 to knock on the door of the house.”)
print_pause(“Enter 2 to peer into the cave.”)
print_pause(“What would you like to do?”)
print_pause(“Please enter 1 or 2.”)

Your code is a little difficult to follow, because you’ve not posted it in a formatted way:

```python
this is where your code should be
```

That said, I can see some fundamental errors:

You don’t need:

import random
from random import choice

Just do from random import choice. Likewise with the time module; just use from time import sleep

Now, when you get to: x=input() the x will hold a string and as such if x == 1: will fail. So, you should use if x == '1': or if int(x) == 1:

Now on the next line (given my comments so far) you can use: print(choice(houses)), but so far as I can tell, all that is going to do (given an input of '1') is to return the memory location of the witch_house function.

edit: correction: ‘witch_house’ is at index zero of the houses list: ‘troll_house’ being at index position 1.

As for elif x > 1 < 3: the same thing applies; you’ve taken a string input, so that branch will fail. Also, I’m not sure what it is that you’re trying to do, as the statement makes no sense to me.

Maybe you mean elif x > 1 or x < 3: in which case you’ll need: elif int(x) > 1 or int(x) < 3:

1 Like

Python has a cool chained comparison, and I suspect the OP actually
wants:

 elif 1 < x < 3:

expressing that x lies between 1 and 3 (exclusive).

Cheers,
Cameron Simpson cs@cskk.id.au

2 Likes