# Build an Apply Discount Function - Build an Apply Discount Function

**URL:** <https://forum.freecodecamp.org/t/build-an-apply-discount-function-build-an-apply-discount-function/788672>\
**Category:** Curriculum Help\
**Tags:** python\
**Created:** [May 12, 2026, 7:58pm UTC](https://forum.freecodecamp.org/t/build-an-apply-discount-function-build-an-apply-discount-function/788672 "2026-05-12T19:58:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![amandasuarez94](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@amandasuarez94](https://forum.freecodecamp.org/u/amandasuarez94)\
**Post date:** [May 12, 2026, 7:58pm UTC](https://forum.freecodecamp.org/t/build-an-apply-discount-function-build-an-apply-discount-function/788672/1 "2026-05-12T19:58:16Z")

</div>

### Tell us what’s happening:

My code isn’t passing the check for “The price should be a number” but I don’t know why? It also won’t pass for any of the steps after even though it returns the correct values.

### Your code so far

```py
def apply_discount(price, discount):
    print(price - price * (discount/100))

    if not isinstance(price, (int, float)):
        return('The price should be a number')
    if not isinstance(discount, (int, float)):
        return('The discount should be a number')
    if price <= 0:
        return('The price should be greater than 0')
    if discount < 0 or discount > 100:
        return('The discount should be between 0 and 100')  
    else:
        cal_dis = (discount/100) * price
        final_price = price - cal_dis   
apply_discount(100,20)  
apply_discount(200,50)
apply_discount(50,0)
apply_discount(150,100)
apply_discount(74.5,20.0)

```

### Your browser information:

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36 Edg/147.0.0.0`

### Challenge Information:

Build an Apply Discount Function - Build an Apply Discount Function

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/python-v9/lab-discount-calculator/build-a-discount-calculator)**
>
> Learn to Code — For Free

Github Link: [freeCodeCamp/curriculum/challenges/english/blocks/lab-discount-calculator/695774002591bbc5f8cf3e53.md at main · freeCodeCamp/freeCodeCamp · GitHub](https://github.com/freeCodeCamp/freeCodeCamp/blob/main/curriculum/challenges/english/blocks/lab-discount-calculator/695774002591bbc5f8cf3e53.md)

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [May 12, 2026, 8:03pm UTC](https://forum.freecodecamp.org/t/build-an-apply-discount-function-build-an-apply-discount-function/788672/2 "2026-05-12T20:03:27Z")

</div>

> [@amandasuarez94](#):
>
> ` print(price - price * (discount/100))`

this is the first line of your function, what happens here when it is not a number? call your function to test with a frist argument that is not a number, like `apply_discount("22", 3)`

---

<div class="post-metadata">

**Author:** ![dhess](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/dhess/32/406235_2.png) [@dhess](https://forum.freecodecamp.org/u/dhess)\
**Post date:** [May 12, 2026, 8:05pm UTC](https://forum.freecodecamp.org/t/build-an-apply-discount-function-build-an-apply-discount-function/788672/3 "2026-05-12T20:05:20Z")

</div>

Hi @amandasuarez94,

> [@amandasuarez94](#):
>
> `print(price - price * (discount/100))`

Does it make sense use price and discount before you have determined if they are a valid int or float.

Also, please wrap your function calls in `print()` to see what your function returns in the console. Is your function returning final\_price?

```auto
apply_discount(200,50)
apply_discount(50,0)
apply_discount(150,100)
apply_discount(74.5,20.0)

```

Happy coding!

---

<div class="post-metadata">

**Author:** ![amandasuarez94](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@amandasuarez94](https://forum.freecodecamp.org/u/amandasuarez94)\
**Post date:** [May 12, 2026, 8:09pm UTC](https://forum.freecodecamp.org/t/build-an-apply-discount-function-build-an-apply-discount-function/788672/4 "2026-05-12T20:09:49Z")

</div>

> [@amandasuarez94](#):
>
> ```auto
> def apply_discount(price, discount):
> print(price - price * (discount/100))
> 
> if not isinstance(price, (int, float)):
> return('The price should be a number')
> if not isinstance(discount, (int, float)):
> return('The discount should be a number')
> if price <= 0:
> return('The price should be greater than 0')
> if discount < 0 or discount > 100:
> return('The discount should be between 0 and 100')  
> else:
> cal_dis = (discount/100) * price
> final_price = price - cal_dis   
> apply_discount(100,20)  
> apply_discount(200,50)
> apply_discount(50,0)
> apply_discount(150,100)
> apply_discount(74.5,20.0)
> 
> ```

Hi! Yes the console was correctly outputting the values, so it was working. Everything worked, it was just giving me an error when I clicked “Check code”

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [May 12, 2026, 8:10pm UTC](https://forum.freecodecamp.org/t/build-an-apply-discount-function-build-an-apply-discount-function/788672/5 "2026-05-12T20:10:28Z")

</div>

did you try calling your functions with arguments that are not numbers?

---

<div class="post-metadata">

**Author:** ![amandasuarez94](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@amandasuarez94](https://forum.freecodecamp.org/u/amandasuarez94)\
**Post date:** [May 12, 2026, 8:16pm UTC](https://forum.freecodecamp.org/t/build-an-apply-discount-function-build-an-apply-discount-function/788672/6 "2026-05-12T20:16:31Z")

</div>

I changed it to this: def apply\_discount(price, discount):

```
if not isinstance(price, (int, float)):

    return('The price should be a number')

if not isinstance(discount, (int, float)):

    return('The discount should be a number')

if price <= 0:

    return('The price should be greater than 0')

if discount < 0 or discount > 100:

    return('The discount should be between 0 and 100')  

else:

    cal_dis = (discount/100) \* price

    final_price = price - cal_dis  

    return(final_price) 

```

apply\_discount(100,20)

apply\_discount(200,50)

apply\_discount(50,0)

apply\_discount(150,100)

apply\_discount(74.5,20.0)

and my code passed but nothing was returned in the console so I’m confused.

---

<div class="post-metadata">

**Author:** ![amandasuarez94](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@amandasuarez94](https://forum.freecodecamp.org/u/amandasuarez94)\
**Post date:** [May 12, 2026, 8:20pm UTC](https://forum.freecodecamp.org/t/build-an-apply-discount-function-build-an-apply-discount-function/788672/7 "2026-05-12T20:20:05Z")

</div>

Yep. I changed all of the returns into prints and then it finally outputted it, but then I also got type errors with my \<= 0 line even though I didn’t previously and didn’t change anything about that line.

---

<div class="post-metadata">

**Author:** ![dhess](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/dhess/32/406235_2.png) [@dhess](https://forum.freecodecamp.org/u/dhess)\
**Post date:** [May 12, 2026, 8:41pm UTC](https://forum.freecodecamp.org/t/build-an-apply-discount-function-build-an-apply-discount-function/788672/8 "2026-05-12T20:41:56Z")

</div>

> [@dhess](#):
>
> Also, please wrap your function calls in `print()` to see what your function returns in the console.

You’re not seeing anything in the console because you did not wrap your function calls in `print()` as asked.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [June 9, 2026, 8:42pm UTC](https://forum.freecodecamp.org/t/build-an-apply-discount-function-build-an-apply-discount-function/788672/9 "2026-06-09T20:42:11Z")

</div>

Closed on June 9, 2026, 8:42pm UTC

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