#!/usr/bin/env python3
###################################################################################
# Python variable scope
###################################################################################
print("Content-Type: text/html \n")     #http header with newline char (required for the web)
print('<pre>')                                      #enhance display for the web

print('Outside the Function...')
outerNum1 = 1000                        #variable defined outside of a functions
outerNum2 = 2000
print(outerNum1, outerNum2)


def  scopeTest( ) : 

    global  outerNum1, inner1;                 #makes outerNum1 and inner1 global variables

    inner1 = 100                               #variable defined inside of a function
    inner2 = 200

    print('Inside the Function...')
    print(outerNum1, outerNum2)                #prints 1000  2000
    print(inner1, inner2)                      #prints 100   200
    outerNum1 = 1500                           #OK - variable is global
#   outerNum2 = 2500                           #ERROR - cannot change variable
    print('After the change:', outerNum1, outerNum2)  #prints 1500  2000

scopeTest( )                                   #call the function

print('Outside the Function...')
print(outerNum1, outerNum2)                    #prints 1500, 2000;
print(inner1)                                  #OK - variable is global
# print(inner2)                                #ERROR - cannot access variable
inner1 = 150                                   #OK - variable is global
print('After the change:', inner1)             #prints 150  

print(''' 
    Variables defined <b>outside</b> of the function are global for read only.
    If you need to update those variable within a function, you must declare those as global.
    Variables defined <b>inside</b> a function cannot be accessed from outside, unless declared as global.
''')