what is wrong in this code? it just prints out the else statement | SoloLearn: Learn to code for FREE!


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)

4/1/2018 5:10:42 PM

Tanvir Hasan

10 Answers

New Answer


Seperate the AND pairs using brackets: https://code.sololearn.com/c1u5zKSBSC34/?ref=app Warning: Not a Python expert


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. ☺


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. ;-)


Tanvir Hasan What Shamima did with the parenthesis is working


thanks for everyone's help.


@James.i know your one's gonna work but why isn't mine working? i've tried adding parenthesis but still isn't working.


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: