Question: I keep getting invalid command when I try to move in a direction In python def main(): def commandshandle(item): print(Directions you can move in are
I keep getting invalid command when I try to move in a direction In python
def main(): 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].upper() 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 else: print("Invalid command. Please try again.") 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() 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
