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!
            Asked
            
        
        
            Active
            
        
            Viewed 51 times
        
    0
            
            
        - 
                    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 Answers
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
- 
                    Important to note that raw_input is no longer available as of Python 3.0 – Stephen Mar 06 '15 at 02:33
- 
                    i tried that too and it wont get rid of the issue which it always outputs guess is too high even when i input '1' and I'm running 2.7 – Jae Song Mar 06 '15 at 02:38
- 
                    I just ran the code with the change suggested: int(input('Enter a number between 1 and 100: ')); and also: print str(guessNum) + " is too low". The code worked fine – Stephen Mar 06 '15 at 02:42
- 
                    
- 
                    I tried the str(guessNum), now it only returns that it is too low instead of too high even when I tried 99 – Jae Song Mar 06 '15 at 02:48
- 
                    
- 
                    Are you sure you changed all the raw_inputs to inputs? It works fine for me when I change it everywhere – Stephen Mar 06 '15 at 04:01
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, inmain() 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
 
     
    