My code meets every story except 7-11, yet I am getting all the desired outputs. Is there any problem with my code that I can improve?
Your code so far
def apply_discount(price,discount):
if not isinstance(price,(int,float)):
return("The price should be a number")
elif not isinstance(discount, (int, 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:
discount = (price*(discount/100))
print(price - discount)
apply_discount(100, 20)
apply_discount(200, 50)
apply_discount(50, 0)
apply_discount(20, 100)
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/151.0.0.0 Safari/537.36
Challenge Information:
Build an Apply Discount Function - Build an Apply Discount Function
Please post your updated code, formatted as follows:
There are two ways you can format your code to make it easier to read and test:
After you copy/paste your code into the editor, select it by dragging your cursor over it then click the (</>) button in the toolbar to automatically wrap your code in backticks. (You can click on the animated demo image below to enlarge it.)
Manually add three backticks on a new line above your code and on a new line after your code. Note that a backtick is NOT the same as a single quote('). To find the backtick key on your keyboard, see this post.
To see changes to your post as you make them, you can click the (M+) button on the toolbar to bring up the rich text editor:
def apply_discount(price,discount):
if not isinstance(price,(int,float)):
return("The price should be a number")
elif not isinstance(discount, (int, 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:
discount = (price*(discount/100))
print(price - discount)
print(apply_discount(100, 20))
print(apply_discount(200, 50))
print(apply_discount(50, 0))
print(apply_discount(20, 100))
print(apply_discount(74.5, 20.0))