from time import sleep def getAnswer(): return raw_input("what do you want to do?") current_location = "forest"; locations = { "forest":{"location":"forest", "short":"you are in a forest. The path goes north and south.", "long":"you are in a deep, dark forest. To the north, a path winds\n off into the distance, and the same is to your south. you think you can just quite make out a light to the north.", "directions":{"north":"house","south":"cave"} }, "house":{"location":"house", "short":"you are in front of a house. The path goes south", "long":"you are in front of a large, ominous house. The door is boarded. a path leads into a forest to the south.", "directions":{"door":"the door is boarded and locked","house":"goto-door","south":"forest"} }, "cave":{ "location":"cave", "short":"NF", "long":"not finished", "directions":{"END":True} } } going = True; while going: print(locations[current_location]["long"]) ans = raw_input(locations[current_location]["long"]) try: current_location = locations[current_location]["directions"][ans] except KeyError: print("I don't know what you meant!") if ans == "quit": going = False;
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question