4 exercises that build on the Python Syntax lesson, from easy to hard. Each one is checked in your browser when you press Check. Stuck? Use the hint before peeking at the solution.
What this lesson covers: Python syntax is the set of rules for writing code Python can understand: one statement per line, run from top to bottom, with indentation showing which lines belong together. By the end you can write and run a small program with print(), add comments, indent a block correctly, and use a SyntaxError message to find and fix a typo. You will practise: Your first program; Fix the shopping list; Predict the output; Battery and signal warnings.
0 / 4 completed
Python Syntax practice exercises
1. Your first program
Write codeEasy✓ Completed
Write a program that prints exactly these two lines:
Hello, Python!
I am learning to code.
Use one print() call for each line. Capital letters and punctuation must match.
Your code
# Write your two print() calls below
Hint: Put each sentence inside quotes, inside the brackets of print(). Check the capital letters and the full stop.
One possible solution
print("Hello, Python!")
print("I am learning to code.")
2. Fix the shopping list
Fix the bugEasy✓ Completed
This program should print the three lines below, but it has two bugs. Run it, read the error, fix that line, then run again until it works.
Hint: The first error points at a piece of text that is never closed. After you fix it, the next error is about a name Python doesn't recognise — look at the capital letters.