By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,621 Members | 1,104 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,621 IT Pros & Developers. It's quick & easy.

Re: for some reason the actual tries figure is not right

P: n/a
En Sat, 24 May 2008 15:32:56 -0300, garywood <wo******@sky.comescribió:
can someone explain why the tries displays the wrong number
orginally i started off with tries = 0 but it was off by 2
How would you count that if you were playing the game "for real"? I'd say that you start (mentally) at 0 and count one more each time the other player says a word.

In your code, there are *two* places where the player inputs his guess. A common idiom is to rearrange the code this way:

tries = 0
while True:
guess = raw_input("Your guess: ")
tries += 1
# break out of the loop when player guesses
if guess==correct:
print "Sorry..."
print "You guessed it in", tries, "tries."

(instead of all those if/else, try to use a dictionary to hold the "hint" corresponding to each word - you might even store several hints, as a tuple)

Gabriel Genellina

Jun 27 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.