Previous Lesson Current Lesson Next Lesson

Question 1

Let’s create a function called sum_numbers as follows:

def sum_numbers(number_one, number_two):
    return number_one + number_two

First, we have to use the keyword def to let Python know that sum_numbers is a function. We then use () to define the parameters to our function, which are in this case number_one and number_two.

We then need to compute a sum of number_one and number_two and output that result using the keyword return in front of the computed sum.

Question 2

In order to sum four numbers, we need to add two more parameters to our original function and add them to the computed sum, as seen below:

def sum_numbers(number_one, number_two, number_three, number_four):
    return number_one + number_two + number_three + number_four