+ 2
Easier way to do this? #SOLVED
CODE LINK: https://code.sololearn.com/cy8bO00Z8a64 I need to check all combinations of rock paper scissors game. I can do this with 9 if`s, but can i do it easier? if img == rock and img2 == rock: res.set("Tie!") if img == rock and img2 == paper: res.set('Computer won!') if img == rock and img2 == scissors: res.set('You won!')
10 Answers
+ 8
Hello Artur
I would use a dictionary. Keys = Rock, Paper and Scissor.
Values = looses against key.
https://code.sololearn.com/c69g4Y8klwfZ/?ref=app
+ 1
I'm sure this could be done with some type of lambda, map thingy where you have lists inside of lists where it returns false or true depending on the case.
+ 1
Thank you, its actually pretty smart and simple!
+ 1
Artur
Your welcome!
0
Can I please see your entire code?
0
Denise, i have a question about line wins[you]==comp. Wins[you] is same as Wins["Rock"] so it returns scissors?
0
Artur
Yes.
dictonary[key] = value
So wins["Rock"] returns "Scissor", wins["Scissor"] returns "Paper" and wins["Paper"] returns "Rock"
0
Whenever I run this code Artur it output is You Win!
0
Ashwin Kumar gavet you changed the key? In this example 'you' is always rock, so output is same every time
0
Ava Alford, you can see the whole code now, i included it to post. But you need to use tkinter and have 5 images in order to make it work