A Review of Functions:
-
Our first look at functions: Ex 5
-
Our second look at functions: Ex 7
-
Hereβs a simple function named gradeCenter() that prints an exercise name description:
python
1def gradeCenter():
2 """Display an Exercise Name"""
3 print("Exercise10")
4
5gradeCenter()Output:
1Exercise10Passing Information to a Function:
- Modified slightly, the function gradeCenter() can not only display the exercise name, Exercise10, but it can also provide a score for the exercise.
- For example, you can enter the score of the exercise in the parentheses of the functionβs definition at def gradeCenter().
- By adding score here you allow the function to accept any value of score you specify.
- For example, you can enter the score of the exercise in the parentheses of the functionβs definition at def gradeCenter().
python
1def gradeCenter(score):
2 print("Exercise10" + score)
3
4gradeCenter(" - Score 100")Output:
1Exercise10 - Score 100- Entering gradeCenter(β - Score 100β) calls gradeCenter() and gives the function the information it needs to execute the print statement.
- Alternatively, entering gradeCenter(β - Score 70)β calls gradeCenter(), passes β- Score 70β, and prints Exercise10 β Score 70.