Python Forum
Number Guessing Game - Need Help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Number Guessing Game - Need Help
#7
Here's some example output when I run your script
Output:
$ python tesit.py In this game you will guess a number and the computer will try to guess it in as few tries as possible. Enter a number 1-100 --- 50 (50, 66, 1, 66) ('\nThe computer guessed ', 66) ('\nThe computer guessed', 15) Traceback (most recent call last): File "tesit.py", line 18, in <module> cNumber = random.randint(placeholder, 1) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py", line 242, in randint return self.randrange(a, b+1) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py", line 218, in randrange raise ValueError, "empty range for randrange() (%d,%d, %d)" % (istart, istop, width) ValueError: empty range for randrange() (66,2, -64)
(Ideally you would have provided this, and saved me the step of creating a file and running it.)

From this, we can narrow your problem to a specific line (18).
cNumber = random.randint(placeholder, 1)
You're calling randint in a way such that you'll always always have this problem as soon as this line is run (unless placeholder happens to be 1).
Output:
>>> random.randint(2, 1) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py", line 242, in randint return self.randrange(a, b+1) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py", line 218, in randrange raise ValueError, "empty range for randrange() (%d,%d, %d)" % (istart, istop, width) ValueError: empty range for randrange() (2,2, 0) >>> random.randint(1, 1) 1
You should start your investigation there.
Reply


Messages In This Thread
RE: Number Guessing Game - Need Help - by micseydel - Jan-04-2018, 12:40 AM
RE: Number Guessing Game - Need Help - by micseydel - Jan-04-2018, 12:41 AM
RE: Number Guessing Game - Need Help - by joekbaum - Jan-04-2018, 12:48 AM
RE: Number Guessing Game - Need Help - by micseydel - Jan-04-2018, 12:59 AM
RE: Number Guessing Game - Need Help - by joekbaum - Jan-04-2018, 01:55 AM
Number Guessing Game - Need Help - by joekbaum - Jan-04-2018, 12:16 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Beginner Boolean question [Guessing game] TKB 4 2,388 Mar-22-2022, 05:34 PM
Last Post: deanhystad
  Unable to count the number of tries in guessing game. Frankduc 7 1,995 Mar-20-2022, 08:16 PM
Last Post: menator01
  Guessing game problem IcodeUser8 7 3,721 Jul-19-2020, 07:37 PM
Last Post: IcodeUser8
  Beginner Code, how to print something after a number of turns (guessing game) QTPi 4 2,817 Jun-18-2020, 04:59 PM
Last Post: QTPi
  Python Help - Guessing Game JamieT 5 2,806 Apr-16-2020, 01:30 PM
Last Post: deanhystad
  Guessing game kramon19 1 2,214 Mar-25-2020, 04:17 AM
Last Post: deanhystad
  Help for guessing game code Kronos 5 3,333 Mar-09-2020, 04:53 PM
Last Post: snippsat
  guessing the number game go127a 6 4,879 Apr-27-2019, 01:23 PM
Last Post: go127a
  Guessing Game does not work the_entrepreneur 3 2,843 Apr-20-2019, 06:19 AM
Last Post: SheeppOSU
  Generating number of objects for a game kom2 3 2,630 Apr-18-2019, 02:04 PM
Last Post: dan789

Forum Jump:

User Panel Messages

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