python code

    

2. Consider the following Python code: 

def next_int1(): cnt = 0 

        cnt += 1
        return cnt

 

global_count = 0 

def next_int2(): global_count += 1 return global_count 

    def main():
        for i = range(0, 5):

print(next_int1(), next_int2()) main() 

  1. (a)  What does the program print?
     
  2. (b)  Whichofthefunctionsnext_int1andnext_int2isthebestfunctionfortheintendedpurpose? Why?
     
  3. (c)  What is a better name for the function named next_int1?
     
  4. (d)  The next_int2 function works in this context, but why is it not a good implementation of
     

 

function that always returns the next largest integer? 

  1. When is the global statement required?
     
Tags: No tags