#πŸ”’ my rock paper scissors aint workin!! keeps saying "syntax error" :(

64 messages Β· Page 1 of 1 (latest)

narrow vapor
#

import random
RPClist = ["rock", "paper", "scissors"]
PlayerChoice = input("this is rock paper scissors. please choose one of three. or else!")
PythonChoice = random.choice(RPClist)

if PlayerChoice == PythonChoice:
print("tie")

elif PlayerChoice == "scissors":
if PythonChoice == "rock":
print("you win!")
else:
print("you lose :(")
elif PlayerChoice =="rock":
if PythonChoice =="paper":
print("you lose :(")
else:
print("you win!")
elif PlayerChoice == "paper":
if PythonChoice == "scissors":
print("you lose :(")
else:
print("you win!")

limpid sequoiaBOT
#

@narrow vapor

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

waxen sand
edgy galleon
#

where does the error say the syntax issue is?

waxen sand
#

I suspect its the else

narrow vapor
waxen sand
narrow vapor
#

i stopped paying attention first marking period and im finally getting my stuff together

#

so im pretty lost

waxen sand
#

After running it in IDLE and getting that error, you should see a red cursor in your file where that error is

narrow vapor
#

same one

waxen sand
#

IDLE isn't making it obvious enough to show where the error is

waxen sand
#

But if I run this in a terminal, it gets a little bit more obvious

#
> py .\pingasrps.py
  File "C:\Users\User\Downloads\pingasrps.py", line 14
    elif PlayerChoice =="rock":
    ^^^^
SyntaxError: invalid syntax
narrow vapor
#

huh

#

it looks fine

waxen sand
#

If its fine, then it wouldn't error πŸ™‚

#

Anyways, do you see the error now?

narrow vapor
#

this is like my first time really trying python

waxen sand
narrow vapor
waxen sand
#

OK. Do you see the line that its pointing at?

narrow vapor
#

line 14

waxen sand
#

yup

#

Do you understand what the error is saying at line 14?

narrow vapor
#

my syntax is off

waxen sand
#

So if else statements always comes as a group

#

1 if, 1 else

#

You can have many elif in between the if and the else

#

But once you have the else, you cannot have an elif after that.

narrow vapor
#

im gonn have to gut my code

waxen sand
#
if bla:
  ...
elif bla1:
  ...
elif bla2:
  ...
else:
  ...
narrow vapor
waxen sand
#

You can move however you want but the structure is always starts with 1 if, then many elifs if any, and then 1 else at the end

#

But looking at your code, you could probably structure it better with and at least when comparing two things

#

e.g.

elif PlayerChoice == "scissors" and PythonChoice == "rock":
  print("you win!")
...
waxen sand
#

Your problem is that you're using nested ifs

waxen sand
narrow vapor
#

could i just put a bunch of those for each combonation

waxen sand
#

you could

narrow vapor
#

thanks man

waxen sand
narrow vapor
#

i have a feeling python thinks they are all connected

waxen sand
narrow vapor
#

i probably need that

#

in retrospect

#

HES WORKING

#

like a well oiled machine

limpid sequoiaBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.