A function is a named block of code that does one job. You can run it whenever you need it by calling its name, and you can give it inputs (called parameters or arguments) and get a result back.
Why functions help: 1) They avoid repetition. Write the code once and reuse it. 2) They make code easier to read, because a good name like calculate_total explains what happens. 3) They make bugs easier to find, because you can test one small piece at a time. 4) They make changes easier. If the rule changes, you fix it in one place.
A practical test: if you copy and paste the same lines more than twice, consider making a function. Aim for each function to do one thing.
What was the first function you wrote?