1.1 Lesson Homework
Lesson 1.1 Homework
Hack 1: Create Your Own Algorithm
Activity chosen: Making a pizza from scratch
Algorithm:
- Gather ingredients: flour, yeast, water, salt, olive oil, tomato sauce, cheese, and toppings.
- Mix flour, yeast, water, salt, and olive oil in a bowl to form dough.
- Knead the dough for about 10 minutes until smooth and elastic.
- Cover the dough with a cloth and let it rise for 1–2 hours.
- Preheat the oven to 475°F (245°C).
- Roll out the dough into a circular shape on a floured surface.
- Spread tomato sauce evenly on the rolled-out dough.
- Add shredded cheese on top of the sauce.
- Place chosen toppings (pepperoni, veggies, etc.) on top of the cheese.
- Put the pizza in the oven and bake for 12–15 minutes.
- Remove pizza from oven, let it cool slightly, then slice and serve.
Hack 2: Identify the Bug
Algorithm (Corrected): Send an Email
- Open email application
- Log into your account
- Enter recipient’s email address
- Write subject line
- Type the message
- Click “Send”
Hack 3: Code the Algorithm
def calculate_grade(score1, score2, score3):
"""
Calculate letter grade from three test scores
Args:
score1, score2, score3: Test scores (integers)
Returns:
grade: Letter grade (string)
"""
# Step 1: Add the three scores together
total = score1 + score2 + score3
# Step 2: Calculate the average
average = total / 3
# Step 3: Determine the letter grade using if-elif-else
if average >= 90:
grade = "A"
elif average >= 80:
grade = "B"
elif average >= 70:
grade = "C"
elif average >= 60:
grade = "D"
else:
grade = "F"
# Step 4: Return the grade
return grade
# Tests
print("Test 1:", calculate_grade(95, 92, 88)) # Should be 'A'
print("Test 2:", calculate_grade(85, 80, 82)) # Should be 'B'
print("Test 3:", calculate_grade(75, 70, 72)) # Should be 'C'
print("Test 4:", calculate_grade(65, 60, 62)) # Should be 'D'
print("Test 5:", calculate_grade(55, 50, 52)) # Should be 'F'
Test 1: A
Test 2: B
Test 3: C
Test 4: D
Test 5: F