Tell us what’s happening:
My code runs OK, as it returns the proper outputs for each situation. However, I am not sure how to complete tests 3, 4, and 5. My code does return the messages like “The price should be a number” when you give it a bad input. Help pls
Your code so far
def apply_discount(price, discount):
if not isinstance(price, int) and not isinstance(price, float):
return('The price should be a number.')
elif not isinstance (discount, int) and not isinstance(discount, float):
return('The discount should be a number.')
elif price <= 0:
return('The price should be greater than zero.')
elif discount < 0 or discount > 100:
return('The discount should be between 0 and 100')
else:
final_price = (1 - (discount/100)) * price
print("Final price: ", final_price)
return final_price
print(apply_discount("p", 20))
Your browser information:
User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Challenge Information:
Build a Discount Calculator - Build a Discount Calculator