Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Apply Discount Based on Total

Apply tiered discounts to a purchase total and return the final amount rounded to two decimals.

Python practice16 minControl Flow (If–Else Logic)IntermediateLast updated March 15, 2026

Problem statement

Write a function apply_discount(total) that applies a discount based on the total amount (a non-negative number): - If total >= 500: apply a 20% discount. - Else if total >= 200: apply a 10% discount. - Else if total >= 100: apply a 5% discount. - Otherwise: no discount. Return the final amount rounded to 2 decimal places (use round(amount, 2)).

Task

Use conditional branching to select the correct discount tier and compute the discounted total.

Examples

Apply 5% discount

Input

apply_discount(120)

Output

114.0

120 >= 100 so 5% off: 120 * 0.95 = 114.0

Input format

A single number total passed to apply_discount(total).

Output format

A number (float) representing the final total after discount, rounded to two decimals.

Constraints

total is a non-negative float or int. Use round(amount, 2) before returning.

Samples

Sample 1

Input

apply_discount(250)

Output

225.0

250 >= 200 -> 10% discount -> 225.0