New Price

Source: Dec 2024, Task 5 (DTU 02002/02003). Study solution — not an official answer key.

Problem

Apply a percent discount, then return (new_price, formatted_string) where the string is the price rounded to two decimals plus ' DKK' (e.g. '86.10 DKK').

Write new_price(price, discount).

Example
>>> new_price(143.50, 40)
(86.1, '86.10 DKK')

Approach

Compute price * (1 - discount/100). Round to 2 decimals for display with an f-string {value:.2f}.

Solution

Show solution Hide solution
Solution
def new_price(price, discount):
    new = price - price * discount / 100
    new = round(new, 2)
    return (new, f"{new:.2f} DKK")