Programming · Grade 7 · Chapter 3
Python Setup & Basic Syntax
Taking your first steps into professional text-based coding.
Chapter Goals
What We Will Master Today
- Environment: Understand how Python reads and runs text code.
- The print() Function: Output text and numbers to the console screen.
- Code Comments: Document code cleanly using the `#` symbol.
- Debugging Syntax Errors: Spot and fix quotes, parens, and case typos.
The Transition
From Blocks to Real Text Code
In Scratch, a missing block just wouldn't snap. In Python, a missing quote mark stops the entire program! Why switch to text code?
Discuss before revealing: Why do real software developers write text code instead of snapping drag-and-drop blocks?
Core Concept 1
How Python Executes Your Code
Python is an interpreted language. The Python Interpreter reads your script line-by-line from top to bottom.
Source Code (.py)
The text file you write in an editor (VS Code, Replit, IDLE).
Console Output
The output window where results and error messages appear.
Developer Workflow
The 4-Step Coding Cycle
Remember: Errors are not failures — they are instructions telling you where to look!
Core Concept 2
The print() Function
print() displays text or values onto the console screen.
print("Hello, World!")
print("Welcome to Grade 7 Computer Science!")
- Function name must be lowercase:
print
- Arguments must be inside parentheses:
()
- Text strings must be inside quotes:
"" or ''
Code Sandbox
Writing Multiple print() Lines
print("Line 1: Loading game...")
print("Line 2: Player connected!")
print("Line 3: Ready to start.")
Rule: Python runs these lines in exact order from top to bottom!
Core Concept 3
Code Comments (#)
Comments are notes written for humans. The Python interpreter completely ignores any line starting with #.
# Author: Alex Smith
# Date: September 2026
# Purpose: Display welcome message
print("Game Initialized") # Inline comment explaining this line
Best Practices
Good Comments vs Bad Comments
✓ Helpful Comment
# Calculate final price with 10% discount
total = price * 0.90
✗ Useless Comment
# Set x to 5
x = 5
Debugging
The 3 Types of Bugs in Python
SyntaxError
Grammar rule broken (missing quote, unclosed paren).
NameError
Using a variable or function name that isn't defined.
LogicError
Code runs without crashing, but gives wrong result!
Spot the Mistake 1
Can You Spot the Missing Quote?
# Broken line:
print("Hello, Python world!)
# Error reported by Python:
SyntaxError: unterminated string literal
Fix: Make sure every opening quote " has a matching closing quote "!
Spot the Mistake 2
Python is Case Sensitive!
# Broken line:
Print("Welcome to class!")
# Error reported by Python:
NameError: name 'Print' is not defined. Did you mean 'print'?
Python treats print, Print, and PRINT as completely different names!
Smartboard Voting
Which Line of Code Will Run Without Error?
Execution Flow
Top-to-Bottom Execution Flow
print("Step A")
print("Step B")
print("Step C")
The console window will ALWAYS print Step A, then Step B, then Step C. Never out of order!
Core Concept 5
Printing Expressions vs Printing Text
Text String (Inside Quotes)
print("5 + 3")
Console Prints: 5 + 3
Math Expression (No Quotes)
print(5 + 3)
Console Prints: 8
Think-Pair-Share
Why Did Python Print 8 vs "5 + 3"?
Quotes tell Python: "Treat this as literal letters/symbols, do not evaluate it as math!"
No quotes tell Python: "Calculate the value of this math expression first, then print the result!"
Quick Check · Quiz 1
Which character is used to create a single-line comment in Python?
Click to reveal answer
Quick Check · Quiz 2
What error occurs if you call Print("Hi") instead of print("Hi")?
ASyntaxError
BNameError
CTypeError
DLogicError
Click to reveal answer
Quick Check · Quiz 3
What will print("10" + "20") display on the screen?
Click to reveal answer
Quick Check · Quiz 4
What happens to comments when Python runs your script?
AThey are printed in green text
BThey are converted to HTML
CThey are completely ignored by the interpreter
DThey cause a SyntaxError
Click to reveal answer
Guided Practice
Fix All Bugs in This Python Script!
# Fix these 3 lines:
Print("Starting program...)
print(Hello world)
#print "Done!"
Goal: Rewrite all 3 lines correctly so the console outputs clean text!
Creative Challenge
ASCII Art with print()
print(" /\\_/\\")
print(" ( o.o )")
print(" > ^ <")
Try drawing a robot or rocket ship using only print() statements!
Summary & Takeaways
What We Learned in Chapter 3
- Python is interpreted top-to-bottom line by line.
print() sends output to the console; quotes mark literal string text.
- Use
# to write clear comments for humans to read.
- Watch out for SyntaxErrors (missing quotes/parens) and NameErrors (capitalization).
Exit Ticket
Create Your 3-Line Python Bio
Write Python code to print:
1. Your name
2. Your favorite subject
3. A comment explaining your code
Next Chapter: Data Types & Operators!