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.
a
b
c
s "message"
def aa b s:
global c
for a in range :
c
s
return a b c s
s
def ba b s:
c
return a b c s
print a
print b
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 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 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
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
