#3.py
 
# When you define variables, always keep in mind the SCOPE of variables.
# That is, which functions can see/access which variables? So far, all the
# variables you have seen were
 
# 1. "local" to the function in which you first defined them, and
# 2. If you make two consecutive calls to the same function you must
#     not assume the local variables will remember values you assigned
#     during the first call. They will not.
 
 
def wait():
    print(" ")
    x = input()

    
# Making count a "global" variable will allow it to retain its value between calls.
# "global" means it is accessible by any function in this module.

count = 5 # Be VERY careful when using globals. Variable count is global to
          # this module and not to the entire program (which may use many modules).

# *** For now my suggestion is NOT to use globals; when we learn about "classes" you
# will meet "static" variables which do what you will need.
 
 
def Larry(x):  # assume first call to Larry is ALWAYS made with x <= 0, say x = -1
               # When Larry completes Larry(-1) it seems that count = 0
    global count
 
    if ( x > 0):       
        print("Second call to Larry, x = ",x,"  count = ",count)                       
 
    if ( x <= 0):
        count = 0
    else:
        count = 1       
 
    return      # no value is being returned. If you do not use an explicit
                # return statement, the function returns anyway.  
 
def main():
 
    #first call to Larry, with parameter set to -1

    #Note: We don't ask Larry() to return any value(s); it must just do some work.

    a = -1
    print("Calling Larry(-1)")
    Larry(a)    # variable a is local to main(); Larry canot see or touch variable a
                # but the value of variable a (i.e., -1) gets put into Larry's parameter, variable x.
                # Variable x is local to Larry; Main cannot see or touch variable x.

                # You can think of variable x as Larry's copy of variable a. They are different entities.
 
 
    #second call to Larry, with parameter set to 1
                
    print("Calling Larry(1)")
    Larry(1)       # this call fails. Python will complain that you are trying to
                   # print a variable (i.e., count) before even giving it a value
 
                   # it "does not remember" variable count or it's value from
                   # the previous call to Larry(0) 
 
              # *if* it did remember, you might have expected it to
              # say "oh, count = 0" because of the previous call
 
              # But it does not!
 
              # Conclusion: functions *** do not remember local variable values
              #             between calls *** (these are called "automatic
              #             variables" -- they come and go) 
 
 
 
#_______________________________________________________________________
