- 3

Please, what is wrong with this code?

print('choose 5 numbers from 0 to 99') numbers= (input("Enter 5 lucky numbers: ")) win = (5, 15, 78, 40, 90) if numbers in win: print('congratulations! you won. your numbers: ', numbers) print('winning numbers: ', win) else: print('you lose.. try again\n') print('winning numbers: ', win)

14th Apr 2022, 11:16 PM
Cletus Charles
16 Antworten
+ 3
Cletus Charles Just tag only that language in which you have problem. You can not check multiple input values like that. numbers in win: Will always return false because numbers can have multiple values
15th Apr 2022, 2:40 AM
A͢J
A͢J - avatar
+ 2
15th Apr 2022, 5:44 AM
Per Bratthammar
Per Bratthammar - avatar
+ 2
Cletus Charles You see, the problem is that it only works if you input one number like 15, but not if you input all five lucky numbers at the same time: 5 15 78 40 90. In the tuple win you have five strings with numbers. But there are no string in the tuple with all five numbers. When you you use numbers = input().split() you create a list with five strings. Every element in the string numbers can now be used to be compared to the strings in the tuple win. Thats the way to go! (Or you have to have five inputs, or change the tuple win to a long string with all numbers in, like win = “5 15 78 40 90”, but that not a good idea…) You also have to think about if the numbers order is of importans. If not and the numbers unique, you can use sets. ) 🙂
15th Apr 2022, 6:36 AM
Per Bratthammar
Per Bratthammar - avatar
15th Apr 2022, 7:06 AM
Lothar
Lothar - avatar
15th Apr 2022, 11:38 PM
Per Bratthammar
Per Bratthammar - avatar
+ 1
Thank you so much Per Bratthammar . I'm grateful
15th Apr 2022, 6:02 AM
Cletus Charles
+ 1
Cletus Charles You can try use a loop an check every inputed value if it is in win. If it is your break. Or count how many of the numbers that where right: mycount = 0 for values in inputedvalues: if values in win: mycount += 1 print(“You had”, mycount, “right!”)
15th Apr 2022, 6:13 AM
Per Bratthammar
Per Bratthammar - avatar
+ 1
Per Bratthammar thanks a lot
15th Apr 2022, 10:33 PM
Cletus Charles
+ 1
Lothar thank you so much. I'm grateful.
15th Apr 2022, 10:34 PM
Cletus Charles
+ 1
Per Bratthammar wow!! Thank you so much 😁
16th Apr 2022, 6:23 AM
Cletus Charles
+ 1
Input function always take string so if you want to input a tuple or a list you have to use loop and take input as int or you have to take int input for 5 numbers individually.
16th Apr 2022, 2:14 PM
Sahil Latif
Sahil Latif - avatar
0
I have edited it. Thank you A͢J
15th Apr 2022, 6:01 AM
Cletus Charles
0
Per Bratthammar what if I want the person to win even if he got one value from win, what will be the code?
15th Apr 2022, 6:04 AM
Cletus Charles
0
Per Bratthammar I just tried another way and I've gotten it. Check it out print('choose 5 numbers from 0 to 99') numbers= (input("Enter 5 lucky numbers: ")) win = ("5", "15", "78", "40", "90") if numbers in win: print('congratulations! you won. your numbers: ', numbers) print('winning numbers: ', win) if numbers not in win: print('you lose.. try again\n') print('winning numbers: ', win)
15th Apr 2022, 6:18 AM
Cletus Charles
0
Cletus Charles it is correct but it will take all inputs in string all numbers you are giving and camparing all are string. So if you want to do in numbers you can check my previous message. If you want I can create code for you.
17th Apr 2022, 5:22 AM
Sahil Latif
Sahil Latif - avatar
- 1
Intendetion,,,, numbers: `, numbers)
16th Apr 2022, 1:52 PM
sunil kumar