How to check if the input matches one of the lucky number and print it? Using python | Sololearn: Learn to code for FREE!

0

How to check if the input matches one of the lucky number and print it? Using python

select=input("please enter your lucky number: ") Luck_number=[1,2,3,4,5,6,7,8,9] if(select==Luck_number[]): print("Congratulations you are the winner") else print("Sorry you did not win! Please try again") end if

8/20/2019 8:52:01 PM

Abdul Hamid Durrani

3 Answers

New Answer

+2

You can do it like this with the in operator: if select in Luck_number: (Also, oooking at your code, you got QUITE a few things wrong. - The input needs to be converted into an integer: select = int(input()) - You don't need the parentheses for the if clause - In python, indentation is VERY important. You can't just do else print(...) you have to do: else: print(...) - Also you don't need "end if" Try to keep things clean, Ok?)

+1

Thank you for your help. I did figure it out as you gave the instruction.

0

You can also:- select = int(input("please enter your lucky number: ")) Luck_number=[1,2,3,4,5,6,7,8,9] print("You winner" if select in Luck_number else "You loose! Please try again") # or print("You winner") if select in Luck_number else print("You loose! Please try again")