Build a Discount Calculator - Build a Discount Calculator

Tell us what’s happening:

I received the result in the terminal exactly as expected from the lab request, but still could not pass the test. I would like to know what is wrong here. Thank you.

Your code so far

def apply_discount(price, discount):
    def calculate_discount():
        final_price = price - (price*discount/100)
        print('Price = ',price)
        print('Discount = ',discount)
        print('Final price = ',final_price)

    check_price = False
    check_discount = False

    if not isinstance(price, (int,float)):
        print('The price should be a number')
    elif price <= 0:
        print('The price should be greater than 0')
    else:
        check_price = True
    
    if not isinstance(discount, (int,float)):
        print('The discount should be a number')
    elif discount < 0 or discount > 100:
        print('The discount should be between 0 and 100')
    else:
        check_discount = True
    
    if check_discount and check_discount:
        calculate_discount()

   
       
apply_discount('abc',101)
apply_discount(100,20)
apply_discount(200,50)
apply_discount(50,0)
apply_discount(100,100)
apply_discount(74.5,20.0)

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0

Challenge Information:

Build a Discount Calculator - Build a Discount Calculator

  1. If price is not a number (int or float), the function should return the string The price should be a number.

return not print.

First for all the code do not print but return all the values and second do not just call calculate_discount() but also return it.:smiling_face_with_three_hearts:

Many thanks, I was able to solved the problem!

1 Like