Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"Guess the Number" game
#12
The problem you have here is you are not keeping the new values. Each time through the loop you assign guess to the correct new_max or new_min, but then you overwrite the other one with the original value. Say the target is 81, and you guess 50, which is too low. You set new_min to 50 and new_max to 100. Then, say you guess 90, which is too high. You set new_max to 90 (good) but then resent new_min back to 1 (bad).

There are two ways to fix this. One is to remove new_max = maximum and new_min = minimum. Of course, this will give you a NameError, because the first time through the loop they will not have been assigned yet. So just before the loop, initialize those variables:

new_max = maximum
new_min = minimum
The other solution would be to get rid of new_max and new_min, and to just modify maximum and minimum directly. So after a low guess, you would have minimum = guess and after a high guess you would have maximum = guess
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
"Guess the Number" game - by CTT - Jul-17-2017, 12:43 PM
RE: "Guess the Number" game - by ichabod801 - Jul-17-2017, 01:13 PM
RE: "Guess the Number" game - by snippsat - Jul-17-2017, 04:16 PM
RE: "Guess the Number" game - by CTT - Jul-18-2017, 10:50 AM
RE: "Guess the Number" game - by ichabod801 - Jul-18-2017, 12:13 PM
RE: "Guess the Number" game - by CTT - Jul-23-2017, 05:22 PM
RE: "Guess the Number" game - by snippsat - Jul-23-2017, 05:59 PM
RE: "Guess the Number" game - by ichabod801 - Jul-23-2017, 08:41 PM
RE: "Guess the Number" game - by CTT - Jul-24-2017, 03:23 AM
RE: "Guess the Number" game - by ichabod801 - Jul-24-2017, 03:52 AM
RE: "Guess the Number" game - by CTT - Jul-24-2017, 02:22 PM
RE: "Guess the Number" game - by ichabod801 - Jul-24-2017, 02:54 PM
RE: "Guess the Number" game - by CTT - Jul-24-2017, 03:19 PM
RE: "Guess the Number" game - by ichabod801 - Jul-24-2017, 04:56 PM
RE: "Guess the Number" game - by sylas - Jul-26-2017, 11:41 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Guess the word game help jackthechampion 3 3,078 Sep-06-2023, 06:51 AM
Last Post: Pedroski55
  Unable to count the number of tries in guessing game. Frankduc 7 1,996 Mar-20-2022, 08:16 PM
Last Post: menator01
  Ask again if wrong guess with While. EduPy 4 2,299 Oct-21-2021, 07:46 PM
Last Post: menator01
  I guess it's about print tsavoSG 2 2,153 Feb-08-2021, 08:34 PM
Last Post: steve_shambles
  Beginner Code, how to print something after a number of turns (guessing game) QTPi 4 2,829 Jun-18-2020, 04:59 PM
Last Post: QTPi
  guessing the number game go127a 6 4,884 Apr-27-2019, 01:23 PM
Last Post: go127a
  Generating number of objects for a game kom2 3 2,638 Apr-18-2019, 02:04 PM
Last Post: dan789
  can't figure out problem with number guess Galoxys 4 3,406 Oct-29-2018, 01:45 PM
Last Post: snippsat
  Guess a number Ameen 5 13,202 Apr-03-2018, 01:20 PM
Last Post: snippsat
  Guess Random Number Why i m not able to enter input Nithya Thiyagarajan 6 8,272 Jan-07-2018, 04:26 AM
Last Post: squenson

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020