# 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/785141>\
**Category:** Curriculum Help\
**Tags:** python\
**Created:** [April 7, 2026, 11:43pm UTC](https://forum.freecodecamp.org/t/build-an-apply-discount-function-build-an-apply-discount-function/785141 "2026-04-07T23:43:49Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [April 8, 2026, 12:09am UTC](https://forum.freecodecamp.org/t/build-an-apply-discount-function-build-an-apply-discount-function/785141/2 "2026-04-08T00:09:25Z")

</div>

Welcome to the forum @hassan12 !

> [@hassan12](#):
>
> ```auto
> if price == 100 and discount == 20:
> return 80
> if price==200 and discount == 50:
> return 100
> if price==74.5 and discount== 20.0:
> return 59.6
> if price == 50 and discount == 0:
> return 50
> 
> if discount == 100:
> return 0
> 
> ```

* * *

It looks like you have hard-coded conditionals or variables that check for specific expected values. That is not solving this problem in the general case. Imagine if you were given different input values. Would your code be able to solve those problems?

To find out more about what hard-coding is or about why it is not suitable for solving coding questions, please read this post: [Hard-coding For Beginners](https://forum.freecodecamp.org/t/hard-coding-for-beginners/703263)

Let us know if you have a question about how to make your code more flexible.

Happy coding!

---

_[View the full topic](https://forum.freecodecamp.org/t/build-an-apply-discount-function-build-an-apply-discount-function/785141)._
