Question: A program is read by computers ( Python interpreters ) and programmers, and sometimes many programmers. It is important to write programs that are readable.

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 identifier like single character as variable name.
It is even worse to have too many identical identifiers as both global variable outside a
function definition and local variable inside a function definition, but they have
entirely different meaning.
A student has submitted a program using a lot of unclear variable identifiers. Please
help the teachers to understand this program.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
a =5
b =2
c =3
s = "message"
def a(a, b, s):
global c
for a in range (3):
c +=1
s =0
return a + b + c + s
s =5
def b(a, b, s):
c =10
return a + b + c + s
print (a(1,2,3))
print (b(1,2,3))
print (s)
(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 a 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 is not exist like the situation in line 16?

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!