From the course: Computer Science Principles: Programming
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Customize functions with parameters
From the course: Computer Science Principles: Programming
Customize functions with parameters
- When we create functions, we take actions and group them together and give them a name. We can then call those actions using the function name and run them as often as we need in our code but sometimes, we want to customize the steps a little bit based on information we might have. Take the example of calculating an order total. Before we calculate a total, there are things like sales tax and shipping cost that might need to be added to the order to give the total cost. So, in our program, we have a variable that contains the price of all the items that are being purchased. We have a function that then calculates the total cost, inside, we add a standard shipping fee and calculate the sales tax at 8% but sales tax rates aren't the same everywhere. Some places have no sales tax, some cities add to the state sales tax, and there can be more variations. So, we need to have a way to take the function for calculating the total cost and modify it. We can do this by using parameters. It…