Question: My code isn't working when I attempt to move from room to room. This is in python. def commandsHandle(item): print(Directions you can move in are

My code isn't working when I attempt to move from room to room. This is in python.

def commandsHandle(item): print("Directions you can move in are North, South, East, West") print("Item available to you in this room, if you choose to accept it: ", item)

while True: asked = input("Please enter: GET or GO : ").split() if asked[0].upper() == "GO": asked[1] = asked[1].capitalize() if asked[1][0] in ['N', 'S', 'E', 'W']: return asked[1] else: continue elif asked[0].upper() == "GET": if asked[1].upper() == item.upper(): return item else: continue

def displayStatus(room, whatYouHave, currentItem): print("You are in the: ", room) print("You already have with you: ", whatYouHave) print("You now have available to you: ", currentItem) print()

# Pseudocode or Flowchart for Code to Get an Item def main(): places = { 'LivingRoom': {'South': 'StorageRoom', 'North': 'Library', 'East': 'Kitchen', 'West': 'BedroomOne'}, 'StorageRoom': {'North': 'LivingRoom', 'East': 'Basement'}, 'Basement': {'West': 'StorageRoom'}, 'BedroomTwo': {'South': 'Kitchen'}, 'BedroomOne': {'East': 'LivingRoom'}, 'Kitchen': {'North': 'BedroomTwo', 'West': 'LivingRoom'}, 'Library': {'East': 'Office', 'South': 'LivingRoom'}, 'Office': {'West': 'Library'} }

arms = { 'LivingRoom': 'n/a', 'Kitchen': 'RottenMeat', 'StorageRoom': 'Medkit', 'Library': 'BookofUndetection', 'Office': 'baseballbat', 'BedroomOne': 'friendone', 'BedroomTwo': 'friendtwo', 'Basement': 'monster' }

where = 'LivingRoom' what = []

while True: displayStatus(where, what, arms[where]) ans = commandsHandle(arms[where]) if ans == arms[where]: what.append(ans) continue else: if ans in places[where]: where = places[where][ans] if where == 'Basement': print("You are now battling the monster...") if len(what) > 3: print("-------------------------------------------") print("You narrowly escaped the mansion with your life") else: print("-------------------------------------------") print("You died :-(") break

else: print() print("No way to go") continue

main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!