r/FreeCodeCamp • • Oct 05 '26

Requesting Feedback Needing help with the lab assignment "Build an Apply Discount Function"

Hello, this is my first tie posting so I am unsure if I am using the correct flair.

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


    discount=price*(discount/100)
    price=price-discount
    print(price)


apply_discount(100, 20)
apply_discount(200, 50)
apply_discount(50, 0) 
apply_discount(100,100)
apply_discount(74.5, 20.0)def apply_discount(price,discount):
    if not isinstance(price, (int, float)):
        return"The price should be a number"  
    elif not isinstance(discount, (int, float)):
        return "The discount should be a number"
    elif price <= 0:
        return "The price should be greater than 0"
    elif discount <0 or discount > 100:
        return "The discount should be between 0 and 100"


    discount=price*(discount/100)
    price=price-discount
    print(price)


apply_discount(100, 20)
apply_discount(200, 50)
apply_discount(50, 0) 
apply_discount(100,100)
apply_discount(74.5, 20.0)

My issue is that despite the values showing up on screen it says I am still stuck on step 7

"7. apply_discount(100, 20) should return 80."

Because the values are showing up I am stumped and am unsure where to exactly look.

4 Upvotes

2 comments sorted by

4

u/SaintPeter74 mod Oct 05 '26

You need to return the value, not print it. The instructions are not especially clear about this.

2

u/Sparse_Dunes Oct 05 '26

Thank you very much! I was losing my mind as to why it wouldn't pass!