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:

1Exercise10

Passing 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.
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.