-1

while loop does not exit

import random
secret_num = random.randint(1, 10)
guess = int(input("Enter your guess: "))
while guess != secret_num:
    guess = input("Please try again: ")
print("Done!")
sshashank124
  • 31,495
  • 9
  • 67
  • 76

1 Answers1

0

As suggested by @DarrylG, you have to convert the input to int.

import random
secret_num = random.randint(1, 10)
guess = int(input("Enter your guess: "))
while guess != secret_num:
    guess = int(input("Please try again: "))
print("Done!")

But remember its random, so you need to try atmax 9 times, to get out of loop.

J Arun Mani
  • 620
  • 3
  • 20