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()
- (a) What does the program print?
- (b) Whichofthefunctionsnext_int1andnext_int2isthebestfunctionfortheintendedpurpose? Why?
- (c) What is a better name for the function named next_int1?
- (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?
- When is the global statement required?