CS101 Functions
This module takes you through functions as a programming concept, functions in Python, and also some practice problems.
StartKey Concepts
Review core concepts you need to learn to master this subject
Function Parameters
Multiple Parameters
Functions
Function Indentation
Calling Functions
Function Arguments
Function Keyword Arguments
Returning Multiple Values
Function Parameters
Function Parameters
def write_a_book(character, setting, special_skill):
print(character + " is in " +
setting + " practicing her " +
special_skill)
Sometimes functions require input to provide data for their code. This input is defined using parameters.
Parameters are variables that are defined in the function definition. They are assigned the values which were passed as arguments when the function was called, elsewhere in the code.
For example, the function definition defines parameters for a character, a setting, and a skill, which are used as inputs to write the first sentence of a book.
- 2Instead of giving those instructions for every hamburger, we can group and name them as a single function: function makeHamburger() { Add bread Add burger patty Add pickles } A function …
- 3Not everyone wants to eat hamburgers. We could write a new function for each new sandwich type, but that takes a lot of work and risks making mistakes. Instead, we’ll generalize the hamburger f…
- 4A sandwich wouldn’t be complete without fries and dessert! Here are the instructions to make the complete meal: * Add bread, Add burger patty, Add fried potatoes, Add pickles, Add bread, Add salt…
- 5Time to get coding! It’s okay if you don’t recognize all the symbols in this code: we’ll walk you through the parts you need to know. The makeSandwich() function is provided in main.js. It is …