1 Nov 2011 02:02
Help
Chris Kavanagh <ckava1 <at> msn.com>
2011-11-01 01:02:46 GMT
2011-11-01 01:02:46 GMT
This code is from the book 'Invent your own computer games with Python'
2nd edition. Great book so far. . .
My question comes on the 2nd game (dragon game). Just a simple little
program that lets you choose to enter 'cave one' or 'cave two' by using
the random module, radnom.randint. If you choose the 'wrong' cave, you
get a message saying 'sorry you've been eaten'. Choose the correct cave
and you get a message that 'you get the treasure. Pretty simple. .
However, I'm confused on Line 30 {if chosenCave== str(friendlyCave)}.
Here's the description of this line the author gives:
"Here we check if the integer of the cave we chose ('1' or '2') is equal
to the cave
randomly selected to have the friendly dragon"
My question is, we saved the integer of the cave we chose in the
variable {cave}in line 15, not {chosenCave}. So, what the heck am I
missing?? How is the {chosenCave} variable now holding the choice I made
in the {cave} variable??
Keep in mind I'm a beginner, but geez, I should understand this easily!
I'm very frustrated right now, I should easily know this. But, I don't,
lol. Thanks in advance for any help!! Code below:
dragon.py
This code can be downloaded from http://inventwithpython.com/dragon.py
If you get errors after typing this code in, compare it to the book's
code with the online
diff tool at http://inventwithpython.com/diff or email the author at
(Continue reading)
RSS Feed