Question: The below is using Python programming A program is read by computers (Python interpreters) and programmers, and sometimes many programmers. It is important to write

The below is using Python programming

A program is read by computers (Python interpreters) and programmers, and sometimes many programmers. It is important to write programs that are readable. A readable program is easy to understand by a human. It is a bad practice to use meaningless identifiers like single characters as variable names. It is even worse to have too many identical identifiers as both global variables outside a function definition and local variables inside a function definition, but they have an entirely different meaning. A student has submitted a program using a lot of unclear variable identifiers. Please help the teachers to understand this program.

The below is using Python programming A program is read by computers

(i) Is there any error when executing this program? If there is no error, write down the output of the program

(ii) Study line 6. The identifier a is used as the name of a function. The same identifier is also used as a local parameter variable. Explain why it is not a problem.

(iii) Study line 7. what is the purpose of putting global in front of the variable c? What will be the difference in the situation of the variable c if the keyword global has not existed like the situation in line 16?

W NP WN = 1 a = 5 2 b 2 3 3 4 S = "message" 5 6 def a(a, b, s): 7 global c 8 for a in range (3): 9 C += 1 10 S = 0 11 return a + b + c + S 12 13 = 5 14 15 def b(a, b, S): 16 C = 10 17 return a + b + c + S 18 19 print (a (1, 2, 3)) 20 print (b(1, 2, 3)) S PPP

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!