syntax error in an if statement at the else ? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: syntax error in an if statement at the else ? (/thread-16631.html) |
syntax error in an if statement at the else ? - Just_started - Mar-07-2019 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) RE: syntax error within def - Yoriz - Mar-07-2019 else shouldn't have a condition its just else: RE: syntax error in an if statement at the else ? - Just_started - Mar-07-2019 Thanks, Yoriz that's exactly what it was. |