0

In my code for guessing game, even when the guess is 1, it returns that the guess is too high. Cant figure it out. Thanks!

Jae Song
  • 29
  • 1
  • 6
  • Aside, your last print line seems to be incomplete. I believe you want to show number of guesses but your `guessCounter` is actually a running list with the `guessNums` appended. So, add a `+ len(guessCounter)` at end of print statement. Also, it wouldn't be average but total. – Parfait Mar 06 '15 at 02:45

2 Answers2

1

Essentially you should not be using raw_input as this will get you a string and not an integer. Try using input

Please see this question for more details: Python read input as integers

Community
  • 1
  • 1
Stephen
  • 1,427
  • 1
  • 17
  • 42
0

Your guessNum is string. Need to make it to int when ever you expect a user to input an integer. For example:

guessNum = int(raw_input('Enter a number between 1 and 100: '))
Marcin
  • 215,873
  • 14
  • 235
  • 294
  • Traceback (most recent call last): File "C:\Users\Jae\Desktop\Scripting\q1", line 23, in main() File "C:\Users\Jae\Desktop\Scripting\q1", line 12, in main print guessNum + " is too low" TypeError: unsupported operand type(s) for +: 'int' and 'str' – Jae Song Mar 06 '15 at 02:35
  • @JeffCrackalack You cant add integers to strings. to do so, need to convert int to string or you string formating. Example of the first case: `str(guessNum) + " is too high, try again:"` and second: `"{} is too high, try again:".format(guessNum)` – Marcin Mar 06 '15 at 02:37
  • can you please examine my comment to the answer(Chuckie) below. I really don't understand why its not printing correctly. Thank you so much – Jae Song Mar 06 '15 at 03:00