Learn Without Walls
← Back to Module 1

Module 1: Practice Problems

💪 Put Your Knowledge to Work!

These 10 problems cover everything from Module 1: what Python is, using print(), comments, running scripts, and the interactive interpreter. Try to solve each problem on your own before looking at the hints or solutions.

Difficulty levels: Easy Medium Challenge

1 Hello, Your Name! Easy

Write a Python program that prints a personalized greeting. Your output should look like this (replace "Maria" with your own name):

Hello, Maria! Welcome to Python programming. Let's get started!
Hint: You need three print() statements, one for each line of output.
Solution:
print("Hello, Maria!")
print("Welcome to Python programming.")
print("Let's get started!")

2 Python Calculator Easy

Use the Python interpreter (or a script) to calculate and display the following:

Hint: Use * for multiplication, ** for exponentiation, and % for remainder (modulo).
Solution:
print("Hours in a year:", 365 * 24)
print("2 to the power of 20:", 2 ** 20)
print("100 divided by 7, remainder:", 100 % 7)
Hours in a year: 8760 2 to the power of 20: 1048576 100 divided by 7, remainder: 2

3 Spot the Errors Easy

Each line below has an error. Identify each error and write the corrected code:

Print("Hello")
print("Good morning')
print "Welcome to Python"
print(Hello, World!)
Hint: Think about capitalization, matching quotes, required parentheses, and when text needs quotes.
Solution:
# Line 1: 'Print' should be lowercase 'print'
print("Hello")

# Line 2: Mismatched quotes (double open, single close)
print("Good morning")

# Line 3: Missing parentheses around the text
print("Welcome to Python")

# Line 4: Text needs to be in quotes
print("Hello, World!")

4 Comment Detective Easy

Look at the following code. What will be printed? (Some lines are comments!)

print("Line A")
# print("Line B")
print("Line C")  # This prints Line C
# print("Line D")
print("Line E")
Hint: Lines starting with # are comments and are completely ignored by Python. Anything after # on the same line is also ignored.
Solution:
Line A Line C Line E

Lines B and D are commented out (they start with #) so they are not executed. The comment after "Line C" on the same line doesn't affect the print statement before it.

5 Type Detective Medium

Without running the code, predict what type() will return for each of the following values. Then check your answers in the interpreter.

type(42)
type(3.0)
type("42")
type(True)
type(7 + 3)
type(7 / 2)
Hint: Remember that quotes make something a string, regular division (/) always returns a float, and expressions are evaluated before type() checks them.
Solution:
type(42)        # <class 'int'> - whole number
type(3.0)       # <class 'float'> - decimal number
type("42")      # <class 'str'> - it's in quotes, so it's text!
type(True)      # <class 'bool'> - boolean value
type(7 + 3)     # <class 'int'> - 7+3=10, which is an int
type(7 / 2)     # <class 'float'> - division ALWAYS returns float

6 Receipt Printer Medium

Write a Python program that prints a simple receipt. Include at least 3 items with prices and a total. Use comments to explain your code. Your output should look something like:

============================ PYTHON STORE ============================ Coffee $4.50 Sandwich $8.99 Cookie $2.75 ---------------------------- Total: $16.24 ============================ Thank you for shopping!
Hint: Use multiple print() statements. You can use spaces to align the prices. Remember to add a comment explaining what the program does!
Solution:
# Receipt Printer Program
# Displays a formatted store receipt

print("============================")
print("       PYTHON STORE")
print("============================")
print("Coffee          $4.50")
print("Sandwich        $8.99")
print("Cookie          $2.75")
print("----------------------------")
print("Total:         $", 4.50 + 8.99 + 2.75)
print("============================")
print("Thank you for shopping!")

7 Math Expressions Medium

Predict the result of each expression, then verify in the Python interpreter:

3 + 4 * 2
(3 + 4) * 2
10 / 3
10 // 3
2 ** 3 ** 2
100 - 25 * 3 + 10
Hint: Remember PEMDAS (Parentheses, Exponents, Multiplication/Division, Addition/Subtraction). Exponentiation (**) is right-associative, meaning 2 ** 3 ** 2 is evaluated as 2 ** (3 ** 2).
Solution:
3 + 4 * 2           # = 3 + 8 = 11
(3 + 4) * 2          # = 7 * 2 = 14
10 / 3               # = 3.3333333333333335 (float division)
10 // 3              # = 3 (integer division, rounds down)
2 ** 3 ** 2          # = 2 ** 9 = 512 (right-associative!)
100 - 25 * 3 + 10   # = 100 - 75 + 10 = 35

8 Script vs. Interpreter Medium

For each scenario, decide whether you would use the interactive interpreter or a script file (.py), and explain why:

  1. Checking what type("hello") returns
  2. Writing a program that displays a multiplication table
  3. Testing whether 10 / 3 gives a whole number or decimal
  4. Creating a homework submission for your Python class
  5. Quickly calculating a tip at a restaurant
Solution:
  1. Interpreter — Quick one-line test to explore a function
  2. Script file — Multi-line program you'd want to save and reuse
  3. Interpreter — Quick test of a single expression
  4. Script file — A program you need to save, submit, and possibly edit later
  5. Interpreter — Quick calculation (e.g., 45.80 * 0.20)

9 Concept Quiz Challenge

Answer the following questions about Python concepts:

  1. What does "dynamically typed" mean in Python?
  2. What is the difference between / and //?
  3. Why is Python called an "interpreted" language?
  4. Name three features that make Python beginner-friendly.
  5. What happens if you try to run a file named python.py?
Solutions:
  1. Dynamically typed means you don't have to declare variable types. Python figures out the type automatically. You write x = 5 instead of int x = 5.
  2. / performs regular division and always returns a float (e.g., 10 / 3 = 3.333...). // performs integer division and rounds down to the nearest whole number (e.g., 10 // 3 = 3).
  3. Python is "interpreted" because it executes code line by line at runtime, rather than compiling the entire program into machine code before running it.
  4. Any three of: readable syntax (reads like English), indentation-based structure, dynamically typed, rich standard library, huge supportive community, error messages are descriptive.
  5. Naming a file python.py can cause Python to try to import your file instead of the actual Python module, leading to confusing errors. Always avoid naming files after Python itself or standard library modules.

10 Build a Business Card Challenge

Create a complete Python script (business_card.py) that displays a nicely formatted business card. Requirements:

Hint: Plan your layout on paper first. Use print("+" + "-" * 30 + "+") to create borders. You can combine text and numbers with commas in print().
Solution (one possible approach):
# Business Card Generator
# Creates a formatted digital business card

print("+------------------------------+")
print("|                              |")
print("|     ALEX JOHNSON             |")
print("|     Software Developer       |")
print("|                              |")
print("|     alex@example.com         |")
print("|     (555) 123-4567           |")
print("|                              |")
print("+------------------------------+")
print()
print("Years of experience:", 5)
Ready for the Quiz? →

Back to Module 1 Home