Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

(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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

ISBN: 0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago