Activity 7

Workshop Resources

Let’s try to create some simple math functions. Create a function called add that takes in two parameters, number1 and number2, and return the sum of the two numbers.

First copy the structure of the triple function. Change the triple function name, and replace the parameter number with number1 and number2, separated with a comma. Both number1 and number2 should be int, and don’t forget to add number1 and number2 together!

To check that your function is working correctly, add the following code after your function definition, which calls the function add() and save its value in a variable. For example:

value2 = add(2, 3)
print("This should print 5: " + str(value2))

Challenge

Can you create functions for subtraction, multiplication, and division?

Test the functions out by calling each function, saving its return value, then printing it out to the console.