+ 1

what is wrong in this code? it just prints out the else statement

a=['rock','paper','scissors'] import random c=random.choice(a) b=input("enter choice: ") computer_score=0 user_score=0 if c=='rock' and b=='scissors' or c=='scissors' and b=='paper' or c=='paper' and b=='rock': computer_score+=1 print(computer_score,user_score) elif b=='rock' and c=='scissors' or b=='scissors' and c=='paper' or b=='paper' and c=='rock': user_score+=1 print(computer_score,user_score) else: print('again?',computer_score,user_score)

1st Apr 2018, 5:10 PM
Tanvir Hasan
Tanvir Hasan - avatar
10 Réponses
+ 7
Seperate the AND pairs using brackets: https://code.sololearn.com/c1u5zKSBSC34/?ref=app Warning: Not a Python expert
1st Apr 2018, 5:46 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 4
I think you might need some parenthesis in your if statements. Like: if (c == 'rock' and b == 'scissors') or (c == 'scissors' and b == 'paper') or (c == 'paper' and b == 'rock'): Group them. Also, it is always more helpful when you post a link to the code. That way we can run it and see what is wrong and help you better. ☺
1st Apr 2018, 5:34 PM
cyk
cyk - avatar
+ 3
It works fine for me Tanvir. I enter "rock", c was "scissors", and it printed "0 1". I win! It then quit, as programmed. Only when I guess the same as the computer (I just threw in a print(c) right before the input to test) does it go to the else. Problem must be you think just like Python. ;-)
1st Apr 2018, 5:46 PM
ServantCoder
ServantCoder - avatar
+ 1
Tanvir Hasan What Shamima did with the parenthesis is working
1st Apr 2018, 5:51 PM
cyk
cyk - avatar
+ 1
thanks for everyone's help.
1st Apr 2018, 6:03 PM
Tanvir Hasan
Tanvir Hasan - avatar
0
@James.i know your one's gonna work but why isn't mine working? i've tried adding parenthesis but still isn't working.
1st Apr 2018, 5:49 PM
Tanvir Hasan
Tanvir Hasan - avatar
0
and........... it's working.but while solving the problem i've come across another one.you see it was giving me the else statement because i was inputing: 'rock' instead of just rock. can anyone tell me why that' s a mistake:
1st Apr 2018, 5:56 PM
Tanvir Hasan
Tanvir Hasan - avatar