Lesson 1 - Test/Quiz
Python Syntax and Data Types – 7 Questions to Cultivate Mastery
Welcome to your Python journey. Let’s take a hands-on approach to learning through thought-provoking questions and relatable examples. Each question will challenge your understanding and introduce new concepts with fresh examples. By the end of this session, you'll feel confident about Python syntax and data types.
Question 1: Can You Fix the Fern’s Growth Report?
The local garden association sent you this Python code to track fern growth, but it’s full of errors. Can you fix it?
Original Code (Broken):
fern_growth_rate = 1.75 inches per week
rose_height = '3.5
is_watered = Yes
print(Fern Growth Rate: fern_growth_rate)
What You Need to Know:
Numbers (like
1.75) should not have extra text.Strings (like
'3.5') must be enclosed in quotes properly.Boolean values are
TrueorFalse, notYes.
Fixed Code:
fern_growth_rate = 1.75 # Float (inches per week)
rose_height = '3.5' # String (in feet)
is_watered = True # Boolean (True means watered)
print("Fern Growth Rate:", fern_growth_rate, "inches per week")
Key Takeaway:
Data types must be used correctly: numbers for measurements, strings for text, and Booleans for yes/no values.
Question 2: Can You Add a New Plant to the Database?
The plant tracker currently only monitors roses. Add a new plant (a tulip) with its growth rate and water status.
Starter Code:
# Current plant data
plant_1 = "Rose"
growth_rate_1 = 2.5 # Inches per week
is_watered_1 = True
# Add a new plant here
What You Need to Know:
Each plant should have its own name, growth rate, and water status.
Use new variable names for the tulip.
Solution:
# Current plant data
plant_1 = "Rose"
growth_rate_1 = 2.5 # Inches per week
is_watered_1 = True
# New plant data
plant_2 = "Tulip"
growth_rate_2 = 1.8 # Inches per week
is_watered_2 = False
print("Plants in the database:")
print(plant_1, "-", growth_rate_1, "inches per week. Watered:", is_watered_1)
print(plant_2, "-", growth_rate_2, "inches per week. Watered:", is_watered_2)
Key Takeaway:
Variables help organize information for multiple entities, like plants.
Question 3: What Happens When We Forget Indentation?
The gardener wrote this script to alert when plants aren’t watered. It’s not working. Why?
Broken Code:
if is_watered == False:
print("Alert: Water the plants!")
What You Need to Know:
Python requires indentation to define code blocks. Without it, the program doesn’t know what belongs inside the
ifstatement.
Fixed Code:
if is_watered == False:
print("Alert: Water the plants!")
Key Takeaway:
Python’s indentation is like spacing rows in a garden—it keeps your code neat and functional.
Question 4: Can You Label the Rows in the Greenhouse?
The greenhouse has three rows of plants: "Daisies", "Lavender", and "Lilies". Write code to store and display these rows.
Starter Code:
# Define rows here
Solution:
# Define rows
row_1 = "Daisies"
row_2 = "Lavender"
row_3 = "Lilies"
print("Greenhouse Rows:")
print("Row 1:", row_1)
print("Row 2:", row_2)
print("Row 3:", row_3)
Key Takeaway:
Strings are ideal for storing text like names or descriptions.
Question 5: Can You Calculate Weekly Water Needs?
Each plant needs a specific amount of water per week. Calculate the total water needed for a rose (2 liters) and a tulip (1.5 liters).
Starter Code:
# Water needs
rose_water = 2
tulip_water = 1.5
# Total water calculation
Solution:
# Water needs
rose_water = 2 # Liters
tulip_water = 1.5 # Liters
# Total water calculation
total_water = rose_water + tulip_water
print("Total water needed:", total_water, "liters")
Key Takeaway:
Numbers can be added, subtracted, multiplied, or divided to perform calculations.
Question 6: How Do We Track Garden Maintenance?
Track whether maintenance tasks have been completed for the day:
Watering.
Fertilizing.
Pest inspection.
Starter Code:
# Define maintenance statuses here
Solution:
# Maintenance statuses
is_watered = True
is_fertilized = False
pests_inspected = True
print("Maintenance Status:")
print("Watered:", is_watered)
print("Fertilized:", is_fertilized)
print("Pests Inspected:", pests_inspected)
Key Takeaway:
Booleans are perfect for tracking yes/no tasks.
Question 7: Can You Describe the Fern’s Current State?
The fern has grown to 15 inches. Write code to display this information, including its name, height, and whether it’s watered.
Starter Code:
# Define fern data here
Solution:
# Fern data
plant_name = "Fern"
current_height = 15 # Inches
is_watered = True
print("Plant Report:")
print("Name:", plant_name)
print("Height:", current_height, "inches")
print("Watered:", is_watered)
Key Takeaway:
Combining different data types (strings, numbers, Booleans) allows you to create detailed, meaningful reports.
Final Reflection
Through these questions, you’ve practiced:
Using data types like numbers, strings, and Booleans.
Following Python’s syntax rules, including proper indentation.
Applying Python to real-world scenarios like tracking plants, water needs, and maintenance.
Take these examples and tweak them! Add new plants, adjust growth rates, or create entirely new scenarios. Every time you practice, you’re planting seeds for a stronger Python foundation. 🌱
