I am doing exercise 36's homework from Learn python 3 the hard way by Zed Shaw. And I am writing Zork-like text adventure. It is in really starting stage. I've tested all of the interactions in the rooms so far and they all work except for one.
I think I am doing a syntax error somewhere, but I can't seem to find where, because I am new to programming.
def room1():
print('You have found a room with three doors: Left, Middle and Right')
choice = input('Where do you want to go?')
if choice == 'left':
room3()
elif choice == 'right':
room2()
elif choice == 'middle':
room5()
else:
print('You must pick one of the three')
def room2():
print('You have found a room with three doors: Left, Middle and Right')
choice = input('Where do you want to go?')
if choice == 'left':
room1()
elif choice == 'right':
room4()
elif choice == 'middle':
room5()
else:
print('You must pick one of the three')
def room3():
print('You enter an empty room, you might want to go back')
choice = input('Do you wish to go back?')
if choice == 'yes':
print('You have returned to the previous room')
room1()
def room4():
print('You have found a room with a portal')
choice = input('Take it?')
if choice == 'yes':
print('You went through it and now you are in another room')
room6()
elif choice == input():
print('You are still in the same room')
else:
print('You must make a decision...')
def room5():
print('You are now in a room with two doors: Left and right, pick one')
choice = input('Left or right?')
if choice == 'left':
room6()
if choice == 'right':
room7()
def room6():
print('You are in a room with a portal inside and a door.')
choice = input('Choose portal or door')
if choice == 'portal':
room4()
if choice == 'door':
broom()
def room7():
print('You are now in a room with two doors: Left and right, pick one')
choice = input('Left or right?')
if choice == 'left':
room5()
if choice == 'right':
broom()
def broom():
print('You enter a room and you trigger a trap')
print('Pick your lucky number to see if you dodge the trap')
choice = input('Lucky number')
if choice > 100:
print('GG')
elif choice < 100:
print('Death by trap')
else:
print('Pick a number!')
def start():
# if start function is on top of code
# it wont work cuz it wont find room 1 and 2
print('This is the start')
print('You have two doors: Left and Right')
choice = input ('Where do you want to go?')
if choice == 'left':
room1()
elif choice == 'right':
room2()
else:
dead('You must pick a door')
start()
I expect to pick a number and the program to check if it is greater than 100 and take the corresponding action (print). And then return at room1. But I get error:
Traceback (most recent call last):
File "pex31.py", line 108, in <module>
start()
File "pex31.py", line 103, in start
room2()
File "pex31.py", line 24, in room2
room4()
File "pex31.py", line 44, in room4
room6()
File "pex31.py", line 68, in room6
broom()
File "pex31.py", line 86, in broom
if choice > 100: