Complete
Stage 3 moves from diagnosis to construction. The learner receives a partially completed technical artifact with meaningful pieces intentionally removed, then uses the surrounding context, requirements, and expected behavior to determine what is missing and complete it.
Concept: Conditional Branching (if, elif, else)
Dataset detected: NO. Generating dummy data.
Hi, I’ve structured the base code, please handle the core logic. Complete the # TODOs. The output must match exactly. Cheers.
🚨 Your objective in this lesson: You must copy the code blocks from each Challenge exactly as they are and paste them into your IDE, then write the missing lines in the code until you achieve the exact Expected Output when running the program.
Challenge 1️⃣: Calculate Package Shipping Cost (Score 3)
🎯 Objective: Implement a basic multi-way conditional branch to assign shipping costs based on weight thresholds.
💻 Expected Output:
Weight: 3kg -> Cost: $10 Weight: 8kg -> Cost: $20 Weight: 25kg -> Cost: $50
Incomplete Code:
def calculate_shipping(weight):
cost = 0
# TODO: Implement conditional logic using if, elif, and else.
# If weight is 20 or more, cost is 50.
# If weight is 5 or more, cost is 20.
# Otherwise, cost is 10.
pass
return cost
packages = [3, 8, 25]
for p in packages:
print(f"Weight: {p}kg -> Cost: ${calculate_shipping(p)}")
Challenge 2️⃣: Categorize User Age Demographics (Score 4)
🎯 Objective: Write the correct if, elif, and else blocks to categorize users based on age ranges.
💻 Expected Output:
Age 10 is categorized as: Child Age 15 is categorized as: Teen Age 25 is categorized as: Adult Age 18 is categorized as: Teen
Incomplete Code:
def categorize_user(age):
category = "Unknown"
# TODO: Use if, elif, and else to set the correct category.
# Less than 13 is 'Child'
# 13 up to 19 (inclusive) is 'Teen' (Hint: strictly less than 20)
# 20 and over is 'Adult'
pass
return category
users = [10, 15, 25, 18]
for u in users:
print(f"Age {u} is categorized as: {categorize_user(u)}")
Challenge 3️⃣: Assign Academic Letter Grades (Score 4)
🎯 Objective: Complete a partially written conditional structure by adding the missing elif and else branches.
💻 Expected Output:
Score: 95 -> Grade: A Score: 82 -> Grade: B Score: 74 -> Grade: C Score: 55 -> Grade: F
Incomplete Code:
def assign_grade(score):
if score >= 90:
return "A"
# TODO: Add an elif branch that returns 'B' for 80 or above.
# TODO: Add an elif branch that returns 'C' for 70 or above.
# TODO: Add an else branch that returns 'F' for anything lower.
pass
scores = [95, 82, 74, 55]
for s in scores:
print(f"Score: {s} -> Grade: {assign_grade(s)}")
Challenge 4️⃣: Determine Loan Eligibility Status (Score 5)
🎯 Objective: Use compound conditions (and / or) inside a multi-way branch to evaluate loan approvals.
💻 Expected Output:
Inc: $60000, Score: 750 -> Approved Inc: $40000, Score: 720 -> Review Inc: $30000, Score: 600 -> Denied
Incomplete Code:
def check_loan_eligibility(income, credit_score):
status = "Pending"
# TODO: Use if, elif, and else to set the status variable.
# 'Approved' if income >= 50000 AND credit_score >= 700.
# 'Review' if income >= 50000 OR credit_score >= 700.
# 'Denied' for all other cases.
pass
return status
applicants = [(60000, 750), (40000, 720), (30000, 600)]
for inc, cred in applicants:
print(f"Inc: ${inc}, Score: {cred} -> {check_loan_eligibility(inc, cred)}")
⚡ Coding5s System – Learn Programming by Writing Code – Coding5S.com
