Section 3.15 π©βπ» Common turtle
Errors
Below weβll describe common errors that beginning programmers encounter when writing turtle code. Some of these errors can be applied to other instances as well!
- Forgetting a Parenthesis
When you run the example above youβll see how an error occurs. This is because we accidentally left off the β)β when we tell alex to move forward. This is a common error for programmers of any skill level - itβs easy to miss one and not notice! If you get a syntax error like this or - especially in this textbook - one that says there was bad syntax on a line that isnβt visible to you, then likely youβre missing a parenthesis, quotation, or bracket.
- Issues with Variable Names
Sometimes we misspell a variable name, either by making it capitalized when it wasnβt previously capitalized or switching letters around. Other times we accidentally refer to the wrong variable name. Checkout the code below for some examples.
- Incorrect Arguments
We can also incorrectly provide arguments to a method or function. When that happens, youβll see an error message like the one below.
We wanted to iterate and draw a square, but we forgot to specify how many times we should iterate over the for loop. As a result, we ran into an error because the range function requires at least one argument. Try fixing this so that the code builds a square. Do you think youβll run into other problems? Predict what will happen and then try it out!
You have attempted of activities on this page.