Level 1: Syntax - IncrediCoders/Python1 GitHub Wiki

GitHubAvatarPoint

Grafika Turtle added this page on March 14, 2025


Here is a bonus article that will tell you more about what Syntax means in computer programming!

In addition to this bonus article, you can find other bonus articles that teach you the topics I covered in Level 1: Object‐Oriented Programming, Troubleshooting & Error Handling and Comments.

Learn About Syntax

When learning to code, understanding syntax is just as important as knowing what each command does. Syntax is the set of rules a programming language follows. Just like a sentence needs to be written the right way to make sense, code needs to be written with the correct syntax so the computer understands what you're asking it to do.

Why Syntax Matters

Even if your logic is correct, the program won’t run unless the syntax is correct too. Think of it like writing a sentence that makes sense. Small mistakes in punctuation or word order can totally change the meaning.

For example, imagine Paul Python writes a note that says:

"go to school Paul Python"

That’s confusing! Is someone telling school to go to Paul Python? Is Paul Python telling someone else to go to school?

Now compare it to:

"Paul Python, go to school!"

With the correct syntax—capitalization, punctuation, and word order—the meaning is clear. Paul Python knows exactly what to do!

Here are some silly examples about how important commas are in the English language:

  • "Let's eat, Grandpa!" vs. "Let's eat Grandpa!": Make sure you include the comma so that you don't eat Grandpa!
  • "Commas are important people!" vs. "Commas are important, people!": I'm pretty sure commas aren't people, right?
  • "I like cooking, my family, and my pets." vs. "I like cooking my family and my pets.": In the first example, you're listing off three things you like! In the second example, I think you're going to jail!

Coding works the same way as grammar, spelling, and punctuation does! If your syntax isn’t right, the computer won’t understand your instructions—-even if your idea makes perfect sense. That’s why paying attention to the little details in your code really matters.

Python Example

Let’s look at how syntax works in real code using a simple example.

Imagine Paul Python wants to eat 5 apples before he leaves for IncrediCoders Academy. You can use a while loop to tell the computer to keep feeding him apples until he’s eaten all 5.

Here’s how the code will look in Python:

apples_eaten = 0
while apples_eaten < 5:
   print("Paul Python eats an apple.")
   apples_eaten += 1

What’s happening here:

  • apples_eaten = 0 sets how many apples Paul has eaten so far.

  • while apples_eaten < 5: means "keep going as long as Paul has eaten fewer than 5 apples."

  • The two indented lines tell the computer what to do each time: print the message and add 1 to the apple count. Each time the while loop runs, Paul eats another apple!

But what if we don’t follow the correct syntax?

apples_eaten = 0
while apples_eaten < 5
print("Paul Python eats an apple.")
apples_eaten += 1
  • The colon (:) is missing after while apples_eaten < 5 on the second line.
  • Indentation: The two lines below the while loop should be indented.

Without following these rules, the computer will get confused and stop. Even though your logic is right, Paul needs to eat apples. The computer doesn’t understand it unless the syntax is correct.

Even if you want Python to understand what you mean, wanting something to happen doesn't make anything happen! For example, if your baby brother was throwing his baby food peas mush into your hair, then wanting him to stop isn't going to get him to stop! You have to take action and do something about it! (And hopefully not hurt your brother.) Python is the same way. You've got to take action to get the result you want!

That’s why syntax is so important! It’s like using good grammar when giving instructions. When your code follows the rules, the computer knows exactly what to do, and Paul Python gets his apples on time!

  • 4 exam--- wut i U yuz orBULL spilling + grammR -QM- T wood B amOS IMP, 2 rd, -> -QM-

Well, that's why the computer complains! Python needs you to write it so that it can understand what you mean! Notice how what I wrote above makes no sense? It only makes sense to me. It's not fair to make you have to read it! That's how the computer feels! (If it was sentient, which it might be one day, so be nice to your computers!) Here's the above paragraph written in the proper grammar:

  • For example, what if you used horrible spelling and grammar? It would be almost impossible to read, right?

Comparing Programming Languages

Different programming languages can follow the same idea (or logic), but they each have their own rules for how you write them. That’s called syntax.

Scenario: If it’s raining, Paul Python brings an umbrella.

Python

is_raining = True
if is_raining:
   print("Paul Python brings an umbrella.")

Java

boolean isRaining = true;
if (isRaining)
{
System.out.println("Paul Python brings an umbrella.");
}

C#

bool isRaining = true;
if (isRaining)
{
Console.WriteLine("Paul Python brings an umbrella.");
}

What's the difference?

  • Even though the code looks different, all three do the same thing.
  • Python is simpler and cleaner for beginners. There are no semicolons, and indentation is used instead of curly braces.
  • Java and C# are stricter about syntax. You must:
    • Clarify that your variable is a Boolean type (for assigning True or False to a variable).
    • Use parentheses for conditions.
    • Use curly braces for blocks.
    • Include semicolons at the end of statements.
  • The print() function in Python is simpler than the equivalent functions in Java and C#.

Syntax is important, because it makes some programming languages easier to use!

Learn More

In the IncrediCoders book, we discuss the topic of syntax on these pages:

  • Page X: Grafika defines syntax. As she says, her brother is named after it!

In the Wiki, we tackle the topic of syntax on these pages:

Next Steps

Next, if you need help completing the Turtle Map project in the book, you can find help at Level 1: Help.

After you complete Level 1 in the book, you can also take on the two extra challenges to add to your Turtle Map program and learn more! When you're done, you can move on to Level 2, the Class Introductions program!

Take the Challenges!

  1. Challenge 1: On this page, I show you how to map a different route to our school, the IncrediCoders Academy. This time, we're going to cross the bridge, over the lake.

  2. Challenge 2: For this challenge, I'll show you how to create a loop, so that you can have the turtle go back and forth between my house and the school, five times.

More Level 1 Resources

In addition to this Bonus Article and the instructions for our Level 1 challenges, we also have Online Articles, a Learning Quiz, an Unplugged Activity, and a Rewards article:

  • Level 1: Online Articles - I made you a list of different web pages I found, which will help you learn more about Turtle Graphics.

  • Level 1: Learning Quiz - I wrote some questions in case you want to quiz yourself about what you learned. Or you can teach others and quiz them! You'll find the answers to the quiz in the Level 1 Solutions folder.

  • Level 1: Unplugged Activity - I wrote this page with more details than what you saw in the book. In this game, you'll have one person act as the Turtle, and one person is the Programmer!

  • Level 1: Rewards - If you completed the Turtle Map project that we talked about in the car, then I set up this page to be your reward. You can see some illustrations of me and learn more about who I am! You'll also find the Turtle Award digital download, to show off your accomplishment!

Level 2

After you're completely done with Level 1 (did you do the challenges?), then it's time to move on to Level 2! While you read through Level 2 in your book, you can check out the resources from Mrs. Scratcher, as she teaches you how to build the Class Introductions program:

I hope you had fun learning about the concept of Syntax! After all, my brother was named after it!

-- Grafika Turtle

⚠️ **GitHub.com Fallback** ⚠️