-1
def guessNum():
    guess = input("guess a number between 1 and 10:  ")
    guesses = 3
    
    randomNum = 7
        
    while guess != randomNum:
        guesses -=1 
        print("wrong," + str(guesses) + "guesses left")
        guess = input("guess again  ")
        if guesses <= 1:
            print("You lose")
            break
        if guess == randomNum:
            print("You win")
            break
        
    
            
print guessNum()

so im having issues with it saying false when its correct. Also when I create a function, it only executes if I give it an input. why does it require an input? cant it have 0 or guessnum(1) and put a random variable when defining it, ie def guessnum(num):

Barmar
  • 741,623
  • 53
  • 500
  • 612
Jeddles
  • 11
  • For one thing, if you are using Python3, you need to convert the input to an number: `guess = int(input("guess a number between 1 and 10: "))` – 001 Nov 18 '21 at 02:13
  • Make sure your move your if(guess == random) statement to the top of your while loop – MFerguson Nov 18 '21 at 02:19

1 Answers1

-1

The problem is that when you input something, it isn't normally an integer. Instead, it's a string. Hence, all you have to do is add the line guess = int(guess) right after the user guesses again.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Ryan Fu
  • 349
  • 1
  • 5
  • 22