All Tracks/lab discount calculator/
Đang tải...
Hướng dẫn thử thách
1 / 1

Build an Apply Discount Function

In this lab you will write a function that calculates the final price of an item after applying a percentage discount. For example, if the price of an item is `50` and a discount of `20` is applied, the discount amount is `10`, and the final price is `40`. **Objective:** Fulfill the user stories below to complete the lab. **User Stories:** 1. You should define a function named `apply_discount`. 2. The `apply_discount` function should take exactly two parameters: `price` and `discount`. 3. If `price` is not a number (`int` or `float`), the function should return the string `The price should be a number`. 4. If `discount` is not a number (`int` or `float`), the function should return the string `The discount should be a number`. 5. If `price` is less than or equal to `0`, the function should return the string `The price should be greater than 0`. 6. If `discount` is less than `0` or greater than `100`, the function should return the string `The discount should be between 0 and 100`. 7. If both inputs are valid, the function should calculate the discount as a percentage of the price. 8. The function should return the final price after applying the discount.
Vượt qua bài kiểm tra hiện tại để mở khóa bài tiếp theo.
main.py
UTF-8 • Tab Size: 2Kiểm tra bài:⌘↵
Test Output
Thử thách này không có bài test tự động. Hãy quan sát kết quả trực tiếp ở khung Preview.