For our final project today we are making a calculator. We will take the first number → then the operation → then the second number → then give the result. This project is broken into task again, and here our task for this project:
But before we begin here is some quick code to go over:
def add(n1, n2):
return n1 + n2
We have seen functions like this before, but we haven't seen the ability to store a function as a value of a variable. To do so we would declare a variable and then put the name of the function without parenthesis. Something like this:
def add(n1, n2):
return n1 + n2
my_favorite_operation = add
print(my_favorite_operation(2, 3))
When we are calling the variable with the function here, we add the parenthesis back and add our parameters.