0

I'm trying to write a program that loops indefinitely. I have a list of numbers and I am supposed to ask the user to guess a number on the list. If the user guesses correctly, then the program should tell them so, and likewise if they guess incorrectly. There should also be an option for the user to stop the infinite loop by typing 'q'. Here is the code that I have written for it...

X = 0

Y = [1, 2, 3, 4, 5, 6]

while X < 1:
    check = input("Guess a number:")
    if check in Y:
        print("You got it right!")
    else:
         if check == "q":
            break
         else:
             if check not in Y:
                 print("Sorry, try again!")


X -= 1

The problem I am running into is that, no matter what number is entered in by the user, the program will always output the "Sorry, try again!" string, even if the number is in fact in the list. The loop does successfully stop if the user types in 'q', but I can not get the program to print "You got it right!". I'm sure that I am just missing something small here, but I would really appreciate it if someone could help me out here. Thank you!

martineau
  • 119,623
  • 25
  • 170
  • 301

0 Answers0