Hardware Reference
In-Depth Information
return value
else:
print(“That is not a recognised answer,;
must be one of “, accepted)
3. Now deine the function handle_room() , which takes the current location,
performs an action based on that location, and then returns the new location.
For example, if the location is start , the game will ask which direction the
player wants to go and use that answer to move the user to a new room.
A
Remember to indent your code correctly here, as three levels of indentation are
being used.
def handle_room(location):
global hp
if location == “start”:
print(“You are standing on a path at the edge of a ;
jungle. There is a cave to your left and a beach to ;
your right.”)
direction = get_input(“Do you want to go left or right? “,
[“left”, “right”])
if direction == “left”:
return “cave”
elif direction == “right”:
return “beach”
elif location == “cave”:
print(“You walk to the cave and notice there is an ;
opening.”)
print(“A small snake bites you, and you lose 20 ;
health points.”)
hp = hp - 20
answer = get_input(“Do you want to go deeper?”,
[“yes”, “no”])
if answer == “yes”:
return “deep_cave”
else:
Search WWH ::




Custom Search