473,789 Members | 2,898 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Michael Dawson's Guess My Number

3 New Member
I am trying to duplicate the Guess My Number Game from Python Programming for the Absolute Beginner by Michael Dawson but for some reason I still cannot figure out my output is not completely correct.
The goal of the program is from the computer to pick a number between 1 and 100 and the user to try to guess the number...if the user choses a number that is too high, the computer will tell the user that their guess is too large and if the number is too low the computer will tell the user that their guess is too small and if the guess is correct, the computer should tell the user "You correctly guessed the number that the computer selected ", print the number and display the number of tries....Can you please help?


Expand|Select|Wrap|Line Numbers
  1. import random
  2. print "\tWelcome to 'Guess My Number' !"
  3. print "\nI'm thinking of a number between 1 and 100."
  4. print "Try to guess it in as few attempts as possible.\n"
  5. the_number = random.randrange(100) + 1
  6. guess = int(raw_input("Take a guess: "))
  7. tries = 1
  8. while (guess != the_number):
  9.             if (guess > the_number):
  10.                 print "The number you guessed is too large"
  11.                 guess = int(raw_input("Take a guess: "))
  12.                 tries +=1
  13.             else:
  14.                 print "The number you guessed is too small"
  15.                 guess = int(raw_input("Take a guess: "))
  16.                 tries +=1
  17.                 print "You correctly guessed the number that the computer    selected ", the_number
  18.                 print "And it only took you", tries, "tries!\n"
  19. raw_input("Press enter to exit")
  20.  
Oct 18 '08 #1
2 4837
numberwhun
3,509 Recognized Expert Moderator Specialist
Almost on the code tags, the \ should be a / on the closing tags.
Oct 18 '08 #2
YarrOfDoom
1,247 Recognized Expert Top Contributor
Since you're learning, I'm only going to give you hints, because people usually learn better if they discover things themselves.
Hint1: Indents decide what code is part of what codeblock.
Hint2: "elif" would be quite handy here.

Try following the execution flow in your mind, and you'll find out what's wrong.
Oct 18 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
12028
by: EAS | last post by:
Hey, I'm new to python (and programming in general) so I'll prolly be around here a lot... Anyways, I've found out how to make a "guess my number game" where the player guesses a number between 1 and 100, but I want to switch things around. I want to be able to put in my own number and have the computer guess it. I already know how to make it guess (by using randrange) but I'm having a hard time making it smarter. (Like guessing higher...
29
2519
by: asj | last post by:
Can you guess what this is? http://www.blueboard.com/phone/apache_sept_2003.gif It's a history of the IIs "Titanic", which is being slowly and painfully sunk by the open source Apache web server. In September, Microsoft's IIs web server again continued to lose marketshare dramatically to the open source Apache web server.
7
1392
by: Calan | last post by:
Mike, Your code on the dynamic input checking was excellent and very well explained. (The only thing I had to do was change the test for text input to be "1 > len of text", instead or "0 > length of text", and add a line to store the result for use on the server). Thank you very much! I have a related issue that you might have some ideas on. In some cases, I have a select box where one of the selections may require an additional input...
0
1076
by: TJB | last post by:
Is there everyone who has knowledge from Tim Dawson's Controls "SandBar" and "SandDocks" ? If so - I have some questions!!!!!! (I know, there is a "Forum" - but there are only PROFESSIONELS, they couldn't help! In this forum i've got as >anonymous< an answer within half an hour - that is GREAT !!!! Thanks User submitted from AEWNET (http://www.aewnet.com/)
2
1542
by: d0ugg | last post by:
Hi, I'm starting to learn C++. And I have this assignment and I can't compile it for some reason.. Here is the problem: -> Write a number guessing name program named guess. The program will generate a pseudo random number in the range 0 to 99. The program will then enter an infinite loop and will: 1 - prompt the user to enter a guess between 0 and 99. 2 - read the guess 3 - if the guess and the random number are equal a - the program...
26
3308
by: Ramon F Herrera | last post by:
http://groups.google.com/group/comp.lang.c/browse_frm/thread/86a3ddf0724d9630/4e38340aa824bee0?lnk=gst&q=how+to+best+parse+a+CSV&rnum=1#4e38340aa824bee0 http://tinyurl.com/29q4kf Michael & Paul (or anyone who can help): I have been looking for a solid implementation of CSV parsing and found the thread above, which includes pointers to programs written by both of you. In my first attempt at building them, I failed miserably, and I
7
2609
by: Suudsu2200 | last post by:
Hi I am making a basic "guess what number I'm thinking of" script and I cant figure out what I'm doing wrong. When I enter my number it changes it to the right number and says correct. (p.s. kinda new so could be dumb mistake) heres my script: <html> <head> <script language="Javascript"> function get_random() {
3
6372
by: willkab6 | last post by:
I am very new to both programming and Pyhton and while trying to do some practice using A byte of python an Error pops up on the IDLE shell. I am using windows XP. PLease see below. while running: guess = int(raw_input('Enter an integer : ')) if guess == number: print 'Congratulations, you guessed it.' running = False # this causes the while loop to stop elif guess < number:
7
16805
by: dseto200 | last post by:
I'm able to create a guessing number game, but I can limit the amount of guesses to less than 3. Can someone tell me what i'm doing wrong? # Guess My Number # The computer picks a random number import random print "\tWelcome to 'Guess my number'!:" print "\nI'm thinking of a number between 1 and 100." print "Try to guess it in as few attempts as possible.\n"
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10410
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9984
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.