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

20th Aug 2019, 8:52 PM
Abdul Hamid Durrani
Abdul Hamid Durrani - avatar
3 odpowiedzi
+ 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?)
20th Aug 2019, 9:14 PM
Airree
Airree - avatar
+ 1
Thank you for your help. I did figure it out as you gave the instruction.
20th Aug 2019, 10:57 PM
Abdul Hamid Durrani
Abdul Hamid Durrani - avatar
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")
23rd Aug 2019, 7:32 PM
rodwynnejones
rodwynnejones - avatar