Build a Discount Calculator - Build a Discount Calculator

Tell us what’s happening:

I have no idea why my function is not returning some but again returning some

Your code so far

def apply_discount (price,discount):
    if not isinstance(price,(int,float)):
        return ("The price should not be a number")
    if not isinstance(discount,(int,float)):
        return ("The discount should not be a number")
    if price <= 0:
        return ("The price should be greater than 0")
    if  not 0 <= discount >= 100:
        return ("The discount should be between 0 and 100")
    
    discount_amount = price * (discount / 100)
    final_price = price - discount_amount
    return final_price

        
        




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

@omega3 create your own topic

If I add print(apply_discount("", 32)), I see The price should not be a number, are you sure that’s the right message? what does the hint say?

1 Like

sorry what do you mean by i should create my topic? i’m new here and i’m also new to python. i really need help please

1 Like

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Get Help > Ask for Help button located on the challenge.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

Welcome to the forum @shaikh.ayaan !

Check the messages you are returning for the first two validations.

Also, what do you see printed when you test, as follows:

print(apply_discount(100,20))
print(apply_discount(200,50))
print(apply_discount(50,0))
print(apply_discount(1,100))
print(apply_discount(74.5,20))
1 Like

for print(apply_discount(74.5,20)) #The price should be a number

I’ve verified my code and they’re all correct. idk y my float doesn’t pass

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.

1 Like