Consider the following Python code

Question # 00778336 Posted By: dr.tony Updated on: 09/24/2020 04:11 AM Due on: 09/24/2020
Subject Education Topic General Education Tutorials:
Question
Dot Image

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?
Dot Image
Tutorials for this Question
  1. Tutorial # 00778146 Posted By: dr.tony Posted on: 09/24/2020 04:12 AM
    Puchased By: 2
    Tutorial Preview
    The solution of Consider the following Python code...
    Attachments
    Consider_the_following_Python_code.ZIP (18.96 KB)

Great! We have found the solution of this question!

Whatsapp Lisa