Problem 1 · Health Metrics
BMI Calculator Utilities
Build a pair of functions: one computes BMI, the other classifies the result into WHO weight
categories.
- Implement
bmi(weight_kg, height_m) returning a float.
- Create
classify_bmi(value) returning a string label.
- Call the helpers from a small script.
def bmi(weight_kg, height_m):
"""Return body mass index using metric units."""
return weight_kg / (height_m ** 2)
def classify_bmi(value):
if value < 18.5:
return "Underweight"
if value < 25:
return "Normal"
if value < 30:
return "Overweight"
return "Obese"
score = bmi(72, 1.78)
print(score, classify_bmi(score))
Problem 2 · Gradebook
Weighted Average Helper
Write a function that calculates a weighted course average by reading score/weight pairs from the
user. The helper returns the normalized average without storing the entries.
- Prompt for the number of components.
- Loop through that many entries, accumulating sums.
- Return the computed value, don’t print from inside the helper.
def weighted_average():
items = int(input("How many graded components? "))
weighted_sum = 0.0
total_weight = 0.0
counter = 0
while counter < items:
score = float(input("Score for component: "))
weight = float(input("Weight (e.g., 0.2): "))
weighted_sum += score * weight
total_weight += weight
counter += 1
if total_weight == 0:
return 0.0
return weighted_sum / total_weight
print("Course average:", round(weighted_average(), 2))
Problem 3 · Currency Helper
AED ↔ USD Converter
Implement a pair of functions to convert between AED and USD using a configurable rate.
- Create
to_usd(amount_aed, rate) and to_aed(amount_usd, rate).
- Call the helpers with user-provided amounts.
- Display formatted output.
def to_usd(amount_aed, rate):
return amount_aed / rate
def to_aed(amount_usd, rate):
return amount_usd * rate
exchange_rate = 3.67
local_amount = float(input("AED amount: "))
foreign_amount = float(input("USD amount: "))
print("AED → USD:", round(to_usd(local_amount, exchange_rate), 2))
print("USD → AED:", round(to_aed(foreign_amount, exchange_rate), 2))