Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 3

81 bytes added, 09:19, 2 June 2017
PART 2 - Providing Functions With Arguments
def sum_numbers(number1, number2):
return int(number1) + int(number2)
</source>'''NOTE:''' Running functions with multiple arguments is the same. When you put a function as a argument of another function, the '''inner-most function will run first''', and the return value will be used as the argument for the '''outer function'''. In the example below, '''sum_numbers(5, 5)''' will return '''10''', thus providing that result to be square with that value '''square( 10 )'''.<br><br>:#Issue the following from the ipython shell to test out passing multiple arguments to the sum_numbers() functionsee what happens:<source>
sum_numbers(5, 10)
sum_numbers(50, 100)
</source>'''NOTE:''' Running functions with multiple arguments is the same. When you put a function as a argument of another function, the '''inner-most function will run first''', and the return the value '''10''' from the will be used as the argument for the '''outer function'''. In the example below, '''sum_numbers(5, 5)''' will return '''10''', thus providing that result to be square with that value '''square( 10 )'''.<br><br>
:#Issue the following to issue a function within another function:<source>
square(sum_numbers(5, 5))
</source> Was the result from running this function with these arguments what you though it would be?
13,420
edits