Changes

Jump to: navigation, search

OPS435 Python Lab 3

335 bytes added, 12:45, 2 June 2017
PART 1 - Providing Functions With Arguments
def square(number):
return number ** 2
</source>'''FYI:'''You may have learned that you multiple a number by itself in order to "square" the number. In many computing languages, this can be performed by the mathematical expression: '''number ** 2'''.<br><br>In this case, your function takes one argument ('''number'''), and the function will perform the mathematical 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>When calling functions that contain arguments to be passed, multiple arguments are separated by '''commas'''. Be careful NOT to provide strings (without using quotes) or using numbers that use decimals in these examples, as you may cause errors.
:#Issue the following to test your '''square()''' function:<source>
square(5)
square(12)
square(square(2))
square('2')</source>Multiple arguments are separated <br><br>The last function called will produce an error message. This is caused by sending a '''commasstring'''instead of a number that is processed by the function. Be careful NOT to provide strings By using the int(without using quotes) or using numbers that use decimals in these examplesfunction, as you may cause errorsany value passed up by a string by mistake will be converted to an integer number.<br><br>
:#Issue the following to declare the function '''sum_numbers()''':<source>
def sum_numbers(number1, number2):
13,420
edits

Navigation menu