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.