This topic is READ ONLY
samist (1) [Avatar] Offline
#1
Hi, I entered the programme exactly in the same way as it is in the book and after some problems managed to run it. But there are problems and problem does this> Afte running this bit appears with no problem: “AHOY! I am Dread Pirate Roberts, and I have a secret! It is a number from 1 to 99. I will give you six tries. What's yer guess?”
And then when I enter a number it doesn’t give me 5 tries but rather this: “58 Too low, ye scurvy dog! No more guesses! Better luck next time matey! The secret number was 83”
But then it keeps asking me what my guess is (What's yer guess?) . So if I entered another number it still would give me the same thing and notify me that the right answer was 83.

Can anyone help with this one?
elliottemartin (1) [Avatar] Offline
#2
Re: Problem with Listing 1.2 - number guessing game
There needs to be a line feed after the line tries = tries + 1. It's hard to tell in the book because the listing is on different pages.
darthbot1 (1) [Avatar] Offline
#3
Re: Problem with Listing 1.2 - number guessing game
I attempted this program but it doesn't work.
import random
secret = random.randint(1,99)
guess = 0
tries = 0
print "Ahoy I am the dread Pirate Roberts. I have a secret!"
print "It is a number from 1 to 99. I'll give you 6 tries."
while guess != secret and tries <6:
guess = input("What's yer guess")
if guess < secret:
print "To low, ye scurvy dog!"
elif guess > secret:
print "Too high, landlubber!"
tries = tries + 1
if guess == secret:
print "Avast! Ye got it! Found my secret, ye did!"
else:
print "No more guesses! Better luck next time,matey!"
print "The secret number was", secret

Help, please.
sandefan (39) [Avatar] Offline
#4
Re: Problem with Listing 1.2 - number guessing game
@darthbot1: why don't you download Listing1.2 from

http://www.manning.com/sande/sourcecode/Zip_Files_By_Chapter/

and compare it, line for line, with your manually entered listing?