Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 syntax error in an if statement at the else ?
#1
Hi, I'm totally a nob to programming and just started with Python, so please forgive me if I'm not yet too familiar with the terms.

I'm trying to define a way which a code can be reuse to allow user to change the color of the turtle object. However, I keep getting error when I run it in the shell.

The error that I get in shell is saying error in line "else pc == "red": saying it is invalid syntax, the line that I ran is square("red").

I appreciate any help anyone can point out.

import turtle
pointer = turtle.Turtle()
increase = input("Enter amount to expand image.")
increase = int(increase)
side = input("How many pixels for each side?")
side = int(side)

def square(pc):
    if pc == "white":
        pointer.color("white")
    elif pc == "black":
        pointer.color("black")
    else pc == "red":
        pointer.color("red")
    for box in range(4):
            pointer.forward(increase*side)
            pointer.right(90)
Quote
#2
else shouldn't have a condition its just
else:
Quote
#3
Thanks, Yoriz that's exactly what it was.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Raise an exception for syntax error sbabu 8 210 Feb-10-2020, 01:57 AM
Last Post: sbabu
  syntax error: can't assign to operator liam 3 280 Jan-25-2020, 03:40 PM
Last Post: jefsummers
  Self taught , (creating a quiz) syntax error on my array DarkAlchemyXEX 9 251 Jan-10-2020, 02:30 AM
Last Post: ichabod801
  If Statements and Comparisons returns a syntax error DarkAlchemyXEX 2 175 Jan-02-2020, 01:25 PM
Last Post: DarkAlchemyXEX
  Syntax Error: Invalid Syntax in a while loop sydney 1 368 Oct-19-2019, 01:40 AM
Last Post: jefsummers
  Syntax error for code that seems correct mcnhscc39 4 815 Nov-15-2018, 08:40 PM
Last Post: j.crater
  Syntax Error bonnerj 1 980 Feb-07-2018, 12:41 PM
Last Post: metulburr
  invalid syntax error penlemon 4 1,243 Jan-27-2018, 02:46 PM
Last Post: sparkz_alot
  Reaction tester syntax error Oli 1 991 Oct-11-2017, 07:26 PM
Last Post: ichabod801
  Syntax error in def Beatenberg 8 2,503 Oct-09-2017, 01:41 PM
Last Post: ichabod801

Forum Jump:


Users browsing this thread: 1 Guest(s)