# File: args2.py # Program to demonstrate how functions handle variables # # Matt Bishop, MHI 289I, Fall 2024 # # # this one shows passing parameters # it just prints the 3 arguments def func1(a, b, c): print("Argument #1:", a) print("Argument #2:", b) print("Argument #3:", c) y = int(b) # # this one defines a local variable, x # and assigns a value to it def func2(): x = 9 print("func2: x =", x) # # this one changes the value of a parameter def func3(y): print("func3: y =", y) y = 3456 print("func3: y =", y) # # this one changes the value of a parameter def func4(y): print("func4: y =", y[0]) y = 3456 print("func4: y =", y) # # the main program # # first, show how arguments are passed func1(7, "3", -3.14159) # now, show how local variables doesn't # affect variables in the caller x = 6 print("main: x =", x) func2() print("main: x =", x) # show how changing parameters # doesn't affect variables in the caller y = 21 print("main: y =", y) func3(y) print("main: y =", y) # finally, show how changing parameters # that are list elements does affect # variables in the caller y = [ 21 ] print("main: y =", y) func4(y) print("main: y =", y)