I have written the steps for this lab, but the result is still blank. It shows the error referring to step 7 ([apply_discount (100, 20)] should return [80]).
def apply_discount (price, discount):
if not isinstance (price, (int or float)):
return ("The price should be a number")
elif not isinstance (discount, (int or float)):
return ("The discount should be a number")
elif price <= 0:
return ("The price should be greater than 0")
elif discount < 0 or discount > 100:
return ("The discount should be between 0 and 100")
else:
apply_discount (100, 20)
sale_price = (price * (1-discount / 100))
return (sale_price)
apply_discount (200, 50)
sale_price = (price * (1-discount / 100))
return (sale_price)
apply_discount (50, 0)
sale_price = (price * (1-discount / 100))
return (sale_price)
apply_discount (0, 100)
sale_price = (price * (1-discount / 100))
return (sale_price)
apply_discount (74.5, 20)
sale_price = (price * (1-discount / 100))
return (sale_price)
I removed the [else:] from the code. The initial error occurs. No returns showing and the error at line 7 of the instructions remain.
def apply_discount(price, discount):
if not isinstance (price, (int or float)):
return ("The price should be a number")
elif not isinstance (discount, (int or float)):
return ("The discount should be a number")
elif price <= 0:
return ("The price should be greater than 0")
elif discount < 0 or discount > 100:
return ("The discount should be between 0 and 100")
apply_discount(100, 20)
sale_price = (price \* (1 - (discount / 100)))
return (sale_price)
apply_discount(0, 100)
sale_price = (price \* (1 - (discount / 100)))
return (sale_price)
apply_discount(200, 50)
sale_price = (price \* (1 - (discount / 100)))
return (sale_price)
apply_discount (74.5, 20.0)
sale_price = (price \* (1 - (discount / 100)))
return (sale_price)