I’m not sure why my statements aren’t passing the tests, am I not supposed to use isinstance?
Your code so far
def apply_discount(price, discount):
if not isinstance(price, (int, float)):
return print('The price should be a number')
if not isinstance(discount, (int, float)):
return print('The discount should be a number')
if price <= 0:
return print('The price should be greater than 0')
if discount < 0 or discount > 100:
return print('The discount should be between 0 and 100')
new_price = price * ((100-discount)/100)
return print(new_price)
apply_discount(100, 20)
Your browser information:
User 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
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')
print(price*(1-discount/100))
Please create your own topic when you have specific questions about your own challenge code. Only respond to another thread when you want to provide help to the original poster of the other thread or have follow up questions concerning other replies given to the original poster.
The easiest way to create a topic for help with your own solution is to click the Ask for Help button located on each challenge. This will automatically import your code in a readable format and pull in the challenge url while still allowing you to ask any question about the challenge or your code.