473,395 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Re: can someone with guessing a number

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
wrong

# 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..."
else:
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
--
http://mail.python.org/mailman/listinfo/python-list
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
0 925

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: sathyashrayan | last post by:
(This is not a home work question) Dear group, I want a program to find one number between a set of natural number.A program to guess a number in between a Natural number set.This should be a...
4
by: moopower | last post by:
I have to do the following: For this project, you are to create a simple number guessing game. The program should begin by asking the user for a range (i.e. a minimum number and a maximum number)...
0
by: Dan Upton | last post by:
On Wed, May 21, 2008 at 12:55 PM, abhilash pp <afilash+python@gmail.comwrote: That won't work as written, because it'll print "you failed," then break, then print "You guessed it!"... As an...
6
by: falconsx23 | last post by:
Hi, I am making a guessing game from the java language. The user is asked to input a number. The number is 1 through a random max number. If the number guessed is correct, then the program should...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.