Build a Discount Calculator - Build a Discount Calculator

Tell us what’s happening:

My ‘Final Price Calculator (after discount)’ works with numbers [integers and floats [+/-]] but I need to know how I can make it work if I feed any of the parameters with words/strings.

Your code so far

# Final Price Calculator (after discount)

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


apply_discount (700, 30)
apply_discount (Ksh 700, 30)
    
        

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Mobile Safari/537.36

Challenge Information:

Build a Discount Calculator - Build a Discount Calculator

Edit: My original code, on an IDE that’s away from freeCodeCamp, had:

discount = discount/100 * price

* I also realized later that I have to include all the parameter examples detailed in the task’s instructions. After I include all the parameters, my Final Price Calculator (after discount) program should work.

Does it make sense to pass a string to a function that calculates a discount on a price?

Do you have a question on your second post in this thread?

1 Like

No, I don’t have any other question for this thread. I realized also that I have not yet met any calculator that allows word-inputs.

this is part that deals with words, it does not allow for words to be used

1 Like

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