🔒 Locked
Python High_Low Game
Advertisement
Original Post
I've been using this tutorial on learning Python http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python/Contents It's a great tutorial, but I'm stuck on one of the exercises. Above they had me create a high_low game with simple code (I'll put it in below), and then in the exercise, they wanted me to take that code and modify it to keep track of how many times the player entered the wrong number. If the number is greater than three times, print "That must have been complicated." I'll show you the main code and the two ways I tried, both are wrong and could use some help on figuring out what my problem is. number = 78 guess = 0 while guess != number: guess = input ("Guess a number: ") if guess > number: print "Too high" elif guess < number: print "Too low" print "Just right" That's the original code number = 78 guess = 0 while guess != number: guess = input ("Guess a number: ") if guess > number: print "Too high" elif guess < number: print "Too low" elif guess > 3 print "That must have been complicated." print "Just right" That was my first attempt and after I ran it I saw the problem, if the number guessed was greater than 3, it would print "Too high" or "Too low" along with "That must have been complicated." number = 78 guess = 0 while guess != number: guess = input ("Guess a number: ") if guess > number: print "Too high" elif guess < number: print "Too low" print "Just right" if guess > 3 print "That must have been complicated." This was my second attempt and I thought it worked, but if you got the correct answer in 1 try it still printed "That must have been complicated." So now I'm stumped, what am I doing wrong? I've wracked my brain trying to figure it out, and I don't know where it is I'm going wrong. Does it have something to do with the guess = 0 at the beginning? *edit* The code was indented in the message, but apparently doesn't show up on the post. :(
I was trying to figure out the exact same thing, but I was already using the random int. Something else I can't figure out though is how to make the program restart after they have finished playing and are prompted with the text: "Would you like to play again Y/N?" . I was told it had to do with loops, but still couldn't figure it out.
edit: sorry didnt see earlier post
[Edited by - shrimpydude on July 19, 2008 7:08:49 PM]
[Edited by - shrimpydude on July 19, 2008 7:08:49 PM]
Hey guys, I was just flipping through the MIT open course ware (which is an excellent resource) and I noticed a course called -
A Gentle Introduction to Programming Using Python
Link:
http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-189January--IAP--2008/CourseHome/index.htm
I remembered glancing at this thread and I figured I'd let you know... may be worth checking out.
A Gentle Introduction to Programming Using Python
Link:
http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-189January--IAP--2008/CourseHome/index.htm
I remembered glancing at this thread and I figured I'd let you know... may be worth checking out.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement