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

Re: can someone with guessing a number

P: n/a
On Wed, May 21, 2008 at 12:42 PM, garywood <wo******@sky.comwrote:
I would just like the program to exit after guessing the amount of numbers

# Guess My Number
import random
the_number = random.randrange(100) + 1
tries = 1
# guessing loop
while (guess != the_number):
if (guess the_number):
print "Lower..."
print "Higher..."

guess = int(raw_input("Take a guess: "))
tries += 1
if tries 10:
print 'you failed- give up'

print "You guessed it! The number was", the_number
print "And it only took you", tries, "tries!\n"

raw_input("\n\nPress the enter key to exit.")

many Thanks
How about you check tries 10 in the condition for your while loop,
and then after the loop you use the value of tries to decide which
message to print out?
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.