from random import choice cave_numbers = range(1,21) wumpus_location = choice(cave_numbers) print wumpus_location player_location = choice(cave_numbers) while player_location == wumpus_location: player_location = choice(cave_numbers) print "Welcome to Hunt the Wumpus!" print "You can see", len(cave_numbers), "caves" print "To play, just type the number" print "of the cave you wish to enter next." while True: print "You are in cave", player_location if (player_location == wumpus_location - 1 or player_location == wumpus_location + 1): print "I smell a wumpus!" print "Which cave next?" player_input = raw_input(">") if (not player_input.isdigit() or int(player_input) not in cave_numbers): print player_input, "is not a cave!" else: player_location = int(player_input) if player_location == wumpus_location: print "Aargh! You got eaten by a wumpus!" break
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