-1

Not sure is wrong here, getting a syntax error on line 19. Deleting the colon moves the error forwards. I think it maybe has something to do with indentation but I'm not sure.

import time 
import random

print('Scissors? Paper? or Rock?')
playerchoice = input()

if playerchoice == 'rock' | 'Rock' | 'ROCK' | 'r' | 'R':
    playerval = 1 
elif playerchoice == 'scissors' | 'Scissiors' | 'SCISSORS' | 's' | 'S':
    playerval = 2
elif playerchoice == 'paper' | 'Paper' | 'PAPER' | 'p' | 'P':
    playerval = 3
else: 
    print('Invalid input')

roboval = (random.randint(0,4)


if roboval == 3 & playerval == 1:
    playerval = 4

if playerval == 3 & roboval == 1: 
    roboval = 4

if playerval > roboval:
    resultwin = 1
else: 
        resultwin = 0
  • 1
    `roboval = (random.randint(0,4)` -- that first open parenthesis shouldn't be there. Voting to close as typo. – wjandrea Aug 14 '20 at 03:58
  • BTW welcome to SO! Check out the [tour], and [ask] if you want advice. In the future, please provide a [mre], which will help find simple typos like this. – wjandrea Aug 14 '20 at 04:00

3 Answers3

2

You want to try and use in statement when you have to check multiple things. Try not to use OR. Also, dont check for each string value. If you know it is going to be ROCK in any variation, then you can convert it to lowercase or uppercase. Python also gives you the startswith() option. So try and use that.

import time 
import random

print('Scissors? Paper? or Rock?')
playerchoice = input()

#instead of OR with a | try and use in
#alternate to this will be
#if playerchoice.lower().startswith('r'):
if playerchoice in ('rock','Rock','ROCK','r','R'):
    playerval = 1 
elif playerchoice in ('scissors','Scissiors','SCISSORS','s','S'):
    playerval = 2
elif playerchoice in ('paper','Paper','PAPER','p','P'):
    playerval = 3
else: 
    print('Invalid input')

roboval = random.randint(0,4) # removed the ( before random.  You don't need that

# instead of & use 'and'
if roboval == 3 and playerval == 1:
    playerval = 4

# instead of & use 'and'
if playerval == 3 and roboval == 1: 
    roboval = 4

if playerval > roboval:
    resultwin = 1
else: 
    resultwin = 0
Joe Ferndz
  • 8,417
  • 2
  • 13
  • 33
0

I see why this error happened. It's a common thing for people who have just transitioned to Python from C, Java, C# etc. I had the opposite problem - I'm new to .NET.

The problem is the & character in your IF statement, change that to the and keyword and you should be good.

EDIT

The above is not true.

Whoops, it's actually a bracket problem just before the if statement.
I find it helps to run it line by line through a syntax checker.
Count the number of opening and closing brackets in the line above.

kettle
  • 412
  • 1
  • 4
  • 11
  • What do you mean by "The above is not true"? OP *should* switch the `&` for `and`, though it's not the cause of the syntax error. – wjandrea Aug 14 '20 at 04:13
-1

Sir, you may need to revise the basics of python 3 again.

First of all, in python |sign is not used for or, nether in C. For or we need to use or in English in line 7,9 and 11. Let me show the correct version:

if playerchoice =='rock' or playerchoice == 'Rock' or playerchoice == 'ROCK' or playerchoice == 'r' or playerchoice == 'R':
    playerval = 1 
elif playerchoice == 'scissors' or playerchoice == 'Scissiors' or playerchoice == 'SCISSORS' or playerchoice == 's' or playerchoice == 'S':
    playerval = 2
elif playerchoice == 'paper' or playerchoice == 'Paper' or playerchoice == 'PAPER' or playerchoice == 'p' or playerchoice == 'P':
    playerval = 3
else: 
    print('Invalid input')

Again, the first error you see is a parenthesis error for this line roboval = random.randint(0,4) See, you opened a parenthesis but didn't close it. You may close the parenthesis or just remove the first one as its not necessary. Do this and I hope it will work.

One more suggestion, print out who won

Ratul Hasan
  • 544
  • 6
  • 14
  • `or` doesn't work how you think it does. See [How to test multiple variables against a value?](https://stackoverflow.com/q/15112125/4518341) – wjandrea Aug 14 '20 at 04:04
  • Actually you needto revise the basics of python too – Onyambu Aug 14 '20 at 04:06
  • tried, or "r" or "rock" or ... works on this case. so didn't change in the first place. but for your words, I changed that to the absolute way. – Ratul Hasan Aug 14 '20 at 05:38