# This code illustrates how scope functions. x = 0 # x is a global variable def main(): # NOT the same x, y, z as in the average function a = 1.3 # local variable to main() b = 2.5 # local variable to main() c = 6.8 # local variable to main() # arguments in a function call do NOT have to have the same # names as formal function parameters x = average(a, b, c) # local x (to main()) being used here print "average =", x if x > 10: var1 = 20 # this variable only exists in # the body of the if statement! # end of var1's scope print var1 # would be illegal! - need to either remove or change def average(x, y, z): # the variables x, y, and z are LOCAL variables to this function # NOT the same as the global x. # If we changed the argument x to say k then the global x value will be used. total = x + y + z # total is another variable, local x being used here return (total / 3.0) main()