Tests 1 to 7 pass, but then the following ones, although the results I get in the console are mathematically correct. Can you please tell me what I do wrong? Maybe I do not understand the assignment?
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:
return (price - discount) / price * 100
print(apply_discount(100, 20))
print(apply_discount(200, 50))
print(apply_discount(50, 0))
print(apply_discount(100, 100))
print(apply_discount(74.5, 20.0))
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/18.3.1 Safari/605.1.15
Challenge Information:
Build a Discount Calculator - Build a Discount Calculator
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.
Yes, sorry, I missed that point. Here is my new code, all tests pass except Nr 9, and I am really wondering why in the console I get 0 as a result instead of 50. Can you pls guide me?
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:
return price - (discount / 100 * price)
print(apply_discount(100, 20))
print(apply_discount(200, 50))
print(apply_discount(50, 0))
print(apply_discount(100, 100))
print(apply_discount(74.5, 20.0))