I cannot get test 4 to work, I need guidance please. Thanks!
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
.
Your code so far
def apply_discount(price, discount):
if price != (int or float):
return 'The price should be a number'
elif price <= 0:
return 'The price should be greater than 0'
elif discount != (int or float):
return 'The discount should be a number'
Your browser information:
UPreformatted textser Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.2 Safari/605.1.15
Challenge Information:
Build a Discount Calculator - Build a Discount Calculator
is this how you check if a value is of a certain data type? you may want to review a couple of lessons before this, like Understanding Variables and Data Types could be appropriate
I changed my code up a bit but when I add the print(apply_discount(50,0))
The only thing that prints is “The price should be a number”
def apply_discount(price, discount):
if isinstance(price, (int, float)):
return 'The price should be a number'
elif price <= 0:
return 'The price should be greater than 0'
elif isinstance(discount, (int, float)):
return 'The discount should be a number'
print(apply_discount(50,0))
def apply_discount(price, discount):
if not isinstance(price, (int, float)):
return 'The price should be a number'
elif price <= 0:
return 'The price should be greater than 0'
elif not isinstance(discount, (int, float)):
return 'The discount should be a number'
elif discount < 0 or discount > 100:
return 'The discount should be between 0 and 100'
return(price - discount)
print(apply_discount(100, 20))
print(apply_discount(200, 50))
print(apply_discount(50, 0))
print(apply_discount(74.5, 20.0))