#WSQ08

The functions are an important part of programming, apparently. Ken says we have to get used to using them and I probably will, some day, I hope. The bright side is that is really easy to define and call functions.

 

For this program we had to go back to the fun with number assignment, but now we are tasked to do the same operations with functions.

 

 

-Creating a function requires to have some established variables, then you have to select the parameters, after that you need to write the statement of the function, and finally you have to write the return statement or the result.

def res (a,b):
n = a – b
print(“The difference of those numbers is: “)
return n

def product (a,b):    
n= a*b                
print(“The product of those numbers is: “)
return n

 

-After you have defined the function you can call the function by writing the name of the function next to the parameters inside a parenthesis.

print (res (a,b))
print (product (a,b))

 

n21

n2.png

 

The program is this:

functions

 

 

 

CC BY-SA 4.0 #WSQ08 by alextenablog is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.