- 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)
16 Answers
+ 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
+ 2
Hi! Cletus Charles !
You can take a look at this one:
https://code.sololearn.com/cDQvSgl14CKS/?ref=app
+ 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. ) 🙂
+ 2
Cletus Charles ,
here some more ideas for you:
https://code.sololearn.com/ciyifXKO4trk/?ref=app
+ 2
Cletus Charles
Hi! Here’s another one:
https://code.sololearn.com/c6BqAt3z9j40/?ref=app
+ 1
Thank you so much Per Bratthammar . I'm grateful
+ 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!”)
+ 1
Per Bratthammar thanks a lot
+ 1
Lothar thank you so much. I'm grateful.
+ 1
Per Bratthammar wow!! Thank you so much 😁
+ 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.
0
I have edited it.
Thank you A͢J
0
Per Bratthammar what if I want the person to win even if he got one value from win, what will be the code?
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)
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.
- 1
Intendetion,,,, numbers: `, numbers)