WSQ08. On to Functions

For this WSQ I had to do the same program as WSQ03, but this time, defining and calling functions.

To define the functions the syntax is:

     def function(a,b):

Where “def” is the command to define the function, “function” is the name of how your function is going to be called and “a” and “b” are the parameters.

In the next line we have to tell the function what to do with the parameters for example:

     def function(a,b):

          print (“The sum of the two numbers is: %s” %(a+b))

Where we are telling it to sum the two parameters but this can vary depending of what you want your function to do.

After defining the function we have to call it and, to do that, the syntax is:

     function(x,y)

Where “x” and “y” are the arguments that you have to define before calling it or ask the user using inputs.

Here is the code: https://www.dropbox.com/s/00kdf1eza50vb1g/wsq08.py?dl=0

 

 

CC BY 4.0 WSQ08. On to Functions by Manuel Madrigal is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.