Build a Discount Calculator - Build a Discount Calculator

I’m struggling with this one a little as well. My code technically meets each objective, since I can get each of the price & discount values calculated as designed, though when I input a string for either, that’s the only part that doesn’t pass the required objectives, though it does say “This should be a number” for each, but it also returns “None” afterward as well. I have looked through this thread and a couple others and I’m wondering if this leeson specifically wants us to use “type()” instead of “isinstance()” since I don’t believe we’ve learned that in the course yet.

Here’s my code:

def apply_discount(price,discount):

if not (isinstance(price, int) or isinstance(price, float)):

    print("The price should be a number")

elif not (isinstance(discount, int) or isinstance(discount, float)):

    print("The discount should be a number")

elif price <= 0:

    print("The price should be greater than 0")

elif discount < 0 or discount > 100:

    print("The discount should be between 0 and 100")

else:

    return (price - (price \* (discount / 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))

print(apply_discount(“five”, 20.0))

print(apply_discount(74.5, “twenty”))

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.

Thank you.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.