I have double checked my code but it keeps saying “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.
Failed:7. apply_discount(100, 20) should return 80.
Failed:8. apply_discount(200, 50) should return 100.
Failed:9. apply_discount(50, 0) should return 50.
Failed:10. When apply_discount is called with a discount of 100, it should return 0.
Failed:11. apply_discount(74.5, 20.0) should return 59.6.“
Your code so far
def apply_discount (price, discount):
if type(price) != int or float:
print('The price should be a number')
if type(discount) != int or float:
print('The discount should be a number')
if price <= 0:
print('The price should be reater than 0')
if discount < 0 or discount > 100:
print('The discount should be between 0 and 100')
if discount and price:
price * discount
print(price)
apply_discount(74.5, 20.0)
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 Edg/145.0.0.0
Challenge Information:
Build a Discount Calculator - Build a Discount Calculator
I updated the code to def apply_discount (price, discount):
if not isinstance(price, (int, float)):
return 'The price should be a number'
if not isinstance(discount, (int, float)):
return ('The discount should be a number')
if price <= 0:
return ('The price should be reater than 0')
if discount < 0 or discount > 100:
return ('The discount should be between 0 and 100')
if discount and price:
price * discount
return (price)
def apply_discount (price, discount):
if not isinstance(price, (int, float)):
return 'The price should be a number'
if not 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')
if discount and price:
discount = discount / 100 * price
price = price - discount
return price
print(price)
apply_discount(50, 0)
Hello? I’ve been stuck on this for a long time, and I have not made any progress. I think the problem is the Python is trying to divide 0 by 100 and is having trouble. Anyone know how to fix this?