unit 3 lesson 5 Flashcards

1
Q

Programming Functions

A

In the previous unit, we learned that a function is a sequence of statements that is only written once but can be called and reused whenever necessary. Functions are a core concept in programming, and you’ll end up using them all the time! In essence functions take in data, process it, and return a result.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Step 1

A

Declare the function with the keyword def followed by the function name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Step 2

A

Write the arguments inside the opening and closing parentheses of the function, and end the declaration with a colon.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Step 3

A

Add the program statements to be executed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Step 4

A

End the function with/without return statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Functions: A guided example

A

Let’s walk through a simple example of writing and calling a function in Python. You need to create a function to add up the amounts on a shopping list to give the total amount the shopper owes when they are at the checkout. To do its job, the function simply needs the list of items the shopper wants to purchase, and it will then look up their prices and add them together.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Conclusion

A

Well it’s been a jam-packed unit, that’s for sure. You’ve learned a fair number of the core building blocks of computer programming, and put them to practice. You stand at the precipice of a whole new world, one full of opportunity and endless creativity. Stay tuned for more binary adventures, and give yourself a pat on the back. You’ve come a long way!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly