Given:
month = ('Jan','Feb','Mar','Apr','May','June','July','Aug','Sep','Oct','Nov','Dec')
expenses = (1800,2700,1202,3100,2100,1750,1845,2234,2141,3010,1911,2950)
Calculate and display:
Your total expenses are: $26,743
Your average expenses are: $2,228.58
- Set
budgetMax = 3000
- Find highest monthly expense
- If any expense exceeds budget, show:
You have exceeded your maximum budget at least once.
The month with the highest expenses is April with $3100.
- Change
budgetMax = 3200 to get:
Congratulations! You kept your budget under control all year.
No loops allowed — use built-in functions only.
💡 Hint 1 — Formatting currency
Use f"${total:,}" for comma-separated integers.
Use f"${avg:,.2f}" for two decimal places with commas.
💡 Hint 2 — Finding the month name
max_exp = max(expenses) gives the highest value.
idx = expenses.index(max_exp) gives its position.
month[idx] gives the month name. But watch out — 'Apr' vs 'April'!
💡 Hint 3 — The budget check (no loops!)
You don't need to loop through expenses. Just check: if max(expenses) > budgetMax: — if the highest exceeds it, at least one did.
▶ Show Solution
month = ('Jan','Feb','Mar','Apr','May','June','July','Aug','Sep','Oct','Nov','Dec')
expenses = (1800,2700,1202,3100,2100,1750,1845,2234,2141,3010,1911,2950)
total = sum(expenses)
avg = total / len(expenses)
print(f"Your total expenses are: ${total:,}")
print(f"Your average expenses are: ${avg:,.2f}")
budgetMax = 3000
max_exp = max(expenses)
idx = expenses.index(max_exp)
if max_exp > budgetMax:
print("You have exceeded your maximum budget at least once.")
print(f"The month with the highest expenses is {month[idx]} with ${max_exp}.")
else:
print("Congratulations! You kept your budget under control all year.")