Changes

Jump to: navigation, search

OPS435 Python Lab 3

119 bytes added, 12:33, 2 June 2017
PART 1 - Providing Functions With Arguments
== PART 1 - Providing Functions With Arguments ==
 :Functions can pass-up '''arguments ''' to be used for processing. In this section, you will learn how to define functions that accept arguments and learn how to perform function calls that pass up arguments for processing (such as mathematical operations or testing conditions (eg. , which is useful for error-checking)).
'''Passing up Single and Multiple Arguments to a Function'''
:#Start the ipython3 shell:<source>
ipython3
</source>When passing arguments up to functions, you MUST contain data such as '''strings''', '''numbers''', or '''variable names''' within '''brackets''' immediately following the function name.<br><br>'''NOTE:''' Normally, when If a function is declared that accepts arguments, then those '''arguments must be declareddefined''' (using variable names)when the function is declared.. Those declared variable names are then used within the function for processing. Also, when you call a function with arguments, the number of arguments passed up to the function must correspond (match) the number of arguments that were specified in the function declaration.<br><br>
:#Issue the following from the ipython shell to declare a function called '''square()''':<source>
def square(number):
return number ** 2
</source>'''FYI:''' To square You may have learned that you multiple a number by itself in math your multiply using '''order to "square" the number * number''' or use exponents . In many computing languages, this can be performed by the mathematical expression: '''number ** 2''' to the power of two. This <br><br>In this case, your function takes one argument ('''number'''), and the function will use exponents to multiply perform the number given by itselfmathematical operation. You should notice that the square of the number sent up to the function , and the result is returned to the main program (in our case, the ipython3 shell).<br><br>
:#Issue the following to test your '''square()''' function:<source>
square(5)
13,420
edits

Navigation menu