๐งช Practice: First Steps
Reading feels like knowing. Typing is knowing. This practice session locks in everything from Module 1 โ no new concepts, just reps.
How it works: solve each exercise in your own file (practice1.py), run it, check your output. Solutions are at the bottom โ attempt first, peek only after a real attempt.
Exercise 1 โ The ritual
Print exactly this (with your own name):
Hello, World!
My name is ____
I am learning PythonExercise 2 โ Fix the broken code
This code has two errors. Find and fix them without rewriting from scratch:
prnt("Hello")
print('Done")Exercise 3 โ One print, three lines
Print this using only one print() statement:
Roses are red
Violets are blue
Python is fun*(Hint: \n inside a string means "new line".)*
Exercise 4 โ The math machine
Print the answers to: 5 + 3, 10 - 4, 6 * 7, and 20 / 4 โ each on its own line, using print with the math *inside* the parentheses (no quotes around the math!).
Then answer: why do the first three print whole numbers but the fourth prints 5.0?
Exercise 5 โ Break and read
Type this *exactly* (yes, it's broken):
print("Counting: 1, 2, 3)
print("Done!")Run it. Read the error out loud, slowly. Fix only what the error complains about. Run again. If a new error appears, read that one too. Repeat until it works.
Solutions
Exercise 1:
print("Hello, World!")
print("My name is Galvan")
print("I am learning Python")Exercise 2: prnt is misspelled (Python only knows print โ a misspelled name gives NameError: name 'prnt' is not defined), and the second line mixes quote types: opens with ' and closes with ". Both must match.
print("Hello")
print('Done')Exercise 3:
print("Roses are red\nViolets are blue\nPython is fun")\n is the newline character โ one string, three printed lines.
Exercise 4:
print(5 + 3) # 8
print(10 - 4) # 6
print(6 * 7) # 42
print(20 / 4) # 5.0The / operator always produces a float (decimal) in Python 3, even when the result is whole: 5.0 not 5. If you want a whole number, use // (floor division): 20 // 4 gives 5.
Exercise 5: The first line is missing its closing quote, so Python reports SyntaxError: unterminated string literal. After fixing it, the program runs โ both lines print.
โ Checkpoint
All five solved from your own keyboard? Module 1 is complete. You can now:
Next module is where Python starts getting *interesting*: the building blocks โ keywords, identifiers, and the tokens that make up every line of code you'll ever write.