1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ollegr [7]
3 years ago
14

3-Write a Python program that has subprograms nested four deep and in which each nested subprogram references local variables, v

ariables defined in all of its enclosing subprograms, and global variables.

Computers and Technology
1 answer:
vivado [14]3 years ago
5 0

Answer:

Explanation:

Below is a little explanation to guide us through;

There are 4 nested methods : level 0, level 1, level 2, and level 3.

Before the methods, there's a global variable defined that can be accessed by all the methods.

Level 0:

This method uses global variable, creates a level 0 variable in its scope, this level 0 variable can be used by all underlying nested methods.

Level 1: this method uses global, level 0, and level 1 variable, which can be accessed by all underlying nested methods: level 2, level 3.

Level 2: similar to te previous ones, it also uses global, level 0, level 1 variables. And creates a level 2 variable that can be accessed by level 3 also.

Level 3:

This method uses all previously created variables, and creates a new level 3 variable.

Function calls:

As you can see, the function calls are part of the method scopes. So, in order to call level 3, we need to access level 2 (because it is getting called from level 2 scope), for level 2, we must call level 1, for which level 0 needs to be called.

So, level 0 is called, which gives its out put and calls level 1, which gives its own output and calls level 2 and so on till level 3 is also called.

CODE:

global_var = "global" #accessible to all functions

def level0():

level0_var = "level 0" #accessible to level 0,1,2,3

print();

print("Level 0 function:")

print("global variable: ",global_var)

print("local variable 0: ",level0_var)

def level1():

print();

print("Level 1 function:")

level1_var = "level 1" ##accessible to level 1,2,3

print("global variable: ",global_var)

print("local variable 0: ",level0_var)

print("local variable 1: ",level1_var)

def level2():

print();

print("Level 2 function:")

level2_var = "level 2" #accessible to level 2,3

print("global variable: ",global_var)

print("local variable 0: ",level0_var)

print("local variable 1: ",level1_var)

print("local variable 2: ",level2_var)

def level3():

print();

print("Level 3 function:")

level3_var = "level 3" #accessible to level 3

print("global variable: ",global_var)

print("local variable 0: ",level0_var)

print("local variable 1: ",level1_var)

print("local variable 2: ",level2_var)

print("local variable 3: ",level3_var)

level3()

level2()

level1()

level0()

attached is the result of the code, also take note of the indentations too

cheers i hope this helps!!!!!

You might be interested in
Encoding is the process:
vodomira [7]

Answer:

Of translating an idea or a thought into a code

Explanation:

Encoding is the process of translating an idea or a thought into a code.

For example:

You want a friend to get you a gaming Laptop as a birthday gift, while describing the specification and how the laptop should look like. You visualize a fast laptop in black cover. You tell your friend it is "fast and portable". You translate your perceptions on a particular laptop into words that describe the model.

5 0
3 years ago
What does FIFO mean?
zubka84 [21]
Hello there!

It is First In First Out

Hope This Helps You!
Good Luck :)
6 0
3 years ago
Read 2 more answers
A network that has locations in different countries is considered a WAN.<br> a. Trueb. False
fiasKO [112]

Answer:

True.

Explanation:

Wide area network (WAN) can be defined as a telecommunication network that covers a wide range of geographical locations such as countries or regions across the world for the purpose of communication and sharing information and data between different users.

Hence, a network that has locations in different countries is considered a wide area network (WAN).

Generally, wide area network (WAN) makes it possible for various organizations to interconnect with their branch offices, headquarters and other multiple locations across the globe. Wide area network (WAN) usually span over a distance of 50 kilometers.

6 0
3 years ago
What is the difference between Windows 7 and Windows 10?
Novay_Z [31]
If you have windows 7 and then change to windows 10, you will see a lot of differences like Microsoft account integration, a new start menu, new apps and a windows store, Cortana and a task view bar, you get edge in windows 10, and most important desktop and security improvements
 Hope this helps!
6 0
3 years ago
What would be a situation in which you could use an Excel chart to present your data?
Minchanka [31]
The second one is correct
5 0
3 years ago
Read 2 more answers
Other questions:
  • Which is a function of network media?
    11·2 answers
  • . A program that can run more than one thread at once is called:
    9·1 answer
  • What makes smartphones so fragile?
    7·1 answer
  • What are the features of Cobol language that make it suitable for programming business applications.
    6·1 answer
  • Which symbol is at the beginning and end of a multiline comment block? ### &amp;&amp;&amp; %%% """
    14·1 answer
  • What games do you play?<br><br><br> Be sure not to report any answers!
    5·1 answer
  • The __________ operator increases the value of the variable by 1 after the original value is used in the expression in which the
    7·1 answer
  • Could someone please help me with this?
    8·1 answer
  • Historia da inteligencia artificial
    6·2 answers
  • Using a text editor, create a file that contains a list of at least 15 six-digit account numbers. Read in each account number an
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!