''' Purpose: try out functions ''' import harb # import access to module harb n1, n2 = 3, 14 # get some values for function exploration n3, n4 = 15, 92 n5, n6 = -6, 53 # Remember that sum had parameters a and b so when we pass in n1 and n2 as ARGUMENTS, # we gave it the explicit values so that the function can use those values. # So parameters are basically filled in by arguments. # a gets 3 (n1) and b gets 14 (n2)! # We assigned the variable t1 the function invocation of sum(n1,n2) # whatever is RETURNED by sum is stored in t1. sum(n1,n2) returns the sum of arguments # n1 and n2 which in this first case would be 3+14 = 17 so t1 = 17. # These function invocations are pass by value (copies of values). # n1 and n2 are not changed! We are just passing copies of those into # the function call to start up the function. # Function call: module_name.function_name(arguments) # Make sure you have your modules and the programs that import/use those modules # in the same folder! # You need to have the same number of arguments to fill in the same number of parameters. # Here, we pass in two arguments (n1 and n2) to fill in two parameters (a and b). # t0 = harb.sum(3,4,5) - Too many arguments! t1 = harb.sum( n1, n2 ) # invoke harb.sum() with arguments n1 and n2 # return value used to set t1 !!! t2 = harb.sum( n3, n4 ) # invoke harb.sum() with arguments n3 and n4 # return value used to set t2 !!! print( "sum(", n1, ",", n2, "):", t1 ) print( "sum(", n3, ",", n4, "):", t2 ) print() i1 = harb.negate( n5 ) # invoke harb.negate() with argument n5 # return value used to set i1 i2 = harb.negate( n6 ) # invoke harb.negate() with argument n6 # return value used to set i2 print( "inverse(", n5, "):", i1 ) print( "inverse(", n6, "):", i2 )