[Solved] Unknown error with my code [closed]


You have one open parenthesis too many on this line:

forward ((int(forward))
#       12   3       32

Remove one at the start:

forward(int(forward))
#      1   2       21

otherwise Python won’t know until the next line that something is missing.

You make the same mistake another two times:

right ((int(right))

and

left ((int(left))

The next problem is that you are trying to use the same name for both a turtle function and a local variable:

forward = input()
forward(int(forward))

This won’t work; Python now sees the string result from input() when referencing forward. Give the result from the input() function a different name:

steps = input()
forward(int(steps))

Again, this applies to the other two functions as well.

Next problem is when you are asking if the user wants to move forward some more:

print "Want to go forward again?  (y) (n)"
moreForward = input()
if moreForward == y:
    turtleFoward()

You are comparing against the global y variable there, not the string 'y'. You probably don’t want to use recursion here either; better make that a loop:

def turtleForward():
    while True:
        steps = input("How far forward do you want to go? ")
        forward(int(steps))
        moreForward = input("Want to go forward again?  (y) (n)")
        if moreForward.lower() != 'y':
            return

4

solved Unknown error with my code [closed]