# File: args.py # Program to demonstrate how functions handle variables # # Matt Bishop, MHI 289I, Fall 2019 # # # 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) # # 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) # # the main program # def main(): # first, show how arguments are passed func1(7, "hello", -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) # finally, show how changing parameters # doesn't affect variables in the caller y = 21 print("main: y =", y) func3(y) print("main: y =", y) main()