انتقل للمحتوى
Robo EgyptRobo Egypt
☰ Course contents
Robo Python: home
0. Lab tour1
1. The start5
2. Variables and input5
3. Conditions5
4. Loops5
5. Lists4
6. Functions4
7. Drawing with the turtle3
8. The project: the guess-the-number game3
9. Strings in depth1
10. Dictionaries (dict)3
11. Randomness and errors3
12. Classes and objects (class)2
13. Pro drawing and charts3
14. The final project: the quiz game2

Comments and errors

Section 1: The startLesson 1.3 · ⏱ 6 min

A line that starts with # is a comment: a note for you, and the computer ignores it.

# this line is a comment
print("Robo")  # a comment at the end of a line
🖥️ The output in Robo Python:
Robo
🐍 Open the code in Robo Python ↗
The example in Robo Python: the code on the right and what appeared on the left
The example in Robo Python: the code on the right and what appeared on the left

If you make a mistake, like forgetting a quotation mark, an error appears in red with the line number. Read the message, go back to the line and fix it. Mistakes are part of learning.

📌 Another example: a comment that explains

Python doesn't run a line that starts with #. We write an explanation for ourselves in it.

🐍 A comment that explains
# this line is a comment: Python skips it
print("Hello")  # a comment can also come after the code
# print("this will not be printed")
🖥️ The output in Robo Python:
Hello
🐍 Open the code in Robo Python ↗
✍️ Practise
Try the lesson's examples here: copy the code, change it, and click ▶ Run.
✍️ Practise here in the lessonor open the lab in a new page ↗

🎯 Challenge yourself

Easy

Write a comment above print that explains what it does.

👀 Show the solution
🐍 Solution
# say hello to the class
print("Hello class")
🖥️ The output in Robo Python:
Hello class
🐍 Open the code in Robo Python ↗

Result: only Hello class, and the comment doesn't appear.

Medium

The code has a mistake: print("Hi). Fix it.

👀 Show the solution
🐍 Solution
print("Hi")
🖥️ The output in Robo Python:
Hi
🐍 Open the code in Robo Python ↗

Result: a quotation mark was missing.

Hard

The code has a mistake: Print("Hi"). Fix it.

👀 Show the solution
🐍 Solution
print("Hi")
🖥️ The output in Robo Python:
Hi
🐍 Open the code in Robo Python ↗

Result: print is written in small letters.

Finished the lesson? Mark it so your progress counts.