Python Forum
syntax error in an if statement at the else ?
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)
Reply


Messages In This Thread
syntax error in an if statement at the else ? - by Just_started - Mar-07-2019, 08:17 PM
RE: syntax error within def - by Yoriz - Mar-07-2019, 08:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Shocked School project -- need help with it it says syntax error XPGKNIGHT 6 3,255 Aug-11-2022, 08:43 PM
Last Post: deanhystad
  I'm getting a syntax error very early on in my code and I can't quite figure it out. liloliveoil 1 1,968 Oct-30-2020, 05:03 AM
Last Post: deanhystad
  Unspecified syntax error hhydration 1 1,963 Oct-25-2020, 10:45 AM
Last Post: ibreeden
  Annuity function for school - syntax error peterp 2 1,928 Oct-12-2020, 10:34 PM
Last Post: jefsummers
  Invalid syntax error, where? tucktuck9 2 3,378 May-03-2020, 09:40 AM
Last Post: pyzyx3qwerty
  Raise an exception for syntax error sbabu 8 3,066 Feb-10-2020, 01:57 AM
Last Post: sbabu
  syntax error: can't assign to operator liam 3 3,994 Jan-25-2020, 03:40 PM
Last Post: jefsummers
  Self taught , (creating a quiz) syntax error on my array DarkAlchemyXEX 9 4,148 Jan-10-2020, 02:30 AM
Last Post: ichabod801
  If Statements and Comparisons returns a syntax error DarkAlchemyXEX 2 2,385 Jan-02-2020, 01:25 PM
Last Post: DarkAlchemyXEX
  Syntax Error: Invalid Syntax in a while loop sydney 1 4,027 Oct-19-2019, 01:40 AM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020