Hardware Reference
In-Depth Information
T
What might happen if a user inputs the item torch when asked to think of an
item? Do you think that the program will print:
A. You could not ind torch
B. Found torch from your backpack
C. A torch! This will shed some light on the matter!
The answer is A. The program prints whatever you type in the string. It does not
currently look inside the inventory list.
Can you think of a way to improve this program so that it checks to see if the item
is already in the list?
Python Text Adventure Game
Text adventure games are fun to create because they are stories written by yourself
that your friends and families can interact with. All you need is a bit of imagination
and, of course, some programming skills.
In this tutorial, you will create your own adventure game that uses text to direct the
player through the game. he program will ask the player to make decisions on what to
do next. his may be as simple as inding out the direction in which she wants to turn
next.
Visit the companion website at www.wiley.com/go/adventuresinrp and
select PythonTextAdventure to see a video of this project.
Getting User Input
As the text adventure game relies on the player (user) to interact with the game to
make decisions, you will need to use the input() function.
direction1 = input(“Do you want to go left or right? “)
Search WWH ::




Custom Search