0

Hi I am new to programming and I like to try to make the code work different way. Unfortunately, variable called unlucky cant be read when printing. So when the user enter the listed value [7 6 5], it doesnt print out as "You have selected unlucky number". I have include the image and copy of my code :

option = int(input("Guess the correct number between 0 to 10 : \nYour choice :"))
unlucky_number= [7,6,5]                        # Unlucky numbers, listed
if  option == unlucky_number:                   # should print somewhere close when user enters list number
    print("You have selected a unlucky number")
elif option== 6:                               # only 6 is correct
    print ("Correct Guess")
elif option in range (0,4):
    print("Not close")
else:
    print ("Not in the range, choose between 1 to 10")

Please tell me whats wrong with it and how can I make a better version of it. Thank you enter image description here

Austin
  • 25,759
  • 4
  • 25
  • 48
Abrar
  • 1
  • _Please tell me whats wrong with it and how can I make a better version of it._ Have you done any debugging? – AMC Apr 29 '20 at 03:44
  • option == unlucky_number is always fails because you are comparing int against list. – lone_ranger Apr 29 '20 at 03:56

1 Answers1

0

if option == unlucky_number This line is causing you troubles. Your "option" holds a singular number, but your "unlucky_number" is a list. List can not be equal to a number, they are completely different animals. What you want is: if option in unlucky_number

Karl Olufsen
  • 186
  • 1
  • 10