i am failing some tests on this code, any idea why?
Your code so far
def apply_discount(price, discount):
if isinstance(price, (int,float)):
return "The price should be a number."
if isinstance(discount, (int,float)):
return "The discount should be a number."
if price <= 0:
return "The price should be greater than 0."
if discount < 0 or discount > 100:
return "The discount should be between 0 and 100."
discount_amount = price * discount / 100
final_price = price - discount_amount
return final_price
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Challenge Information:
Build a Discount Calculator - Build a Discount Calculator
The function seems to be working fine.
4 test cases seems to be failing over and over
Failed:3. When apply_discount is called with a price (first argument) that is not a number (int or float) it should return The price should be a number.
Failed:4. When apply_discount is called with a discount (second argument) that is not a number (int or float) it should return The discount should be a number.
Failed:5. When apply_discount is called with a price lower than or equal to 0, it should return The price should be greater than 0.
Failed:6. When apply_discount is called with a discount lower than 0 or greater than 100, it should return The discount should be between 0 and 100.
make sure to confront what the function is returning vs what it should return, double check spacing and punctuation, the string must be exactly the same