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
What are the two basic windows 8 settings for network security?
maks197457 [2]

The two basic windows 8 setting for network security are Public and private network. The private network settings mean that you can link home group and make remote desktop connections. Public network settings entail the greatest privacy. You should make sure file or device sharing is disabled for having data copy.

<span> </span>

 

7 0
3 years ago
Examine the information in the URL below.
ololo11 [35]

Answer:

B The subdomain is /home/ and the domain name is http://.

Explanation:

7 0
3 years ago
Compare this country early use of credit to its use today?
Stolb23 [73]

Answer:

Explanation:

A credit is a financial transaction where someone takes a loan for a certain amount of money to another person, and this another must pay this money in a period of time, determinate from both parts, in this case, a country can get a credit, if this country pay this debt, the country will have a good record, and they can to ask another credit, but if they don't pay, the debt will be bigger.

7 0
3 years ago
Which set of skills must a network administrator and a systems administrator both have?
Andreyy89
I think the answer to this is A
6 0
3 years ago
Where do you find southwest's flight schedule on their website
slega [8]

Answer:

Right here : https://www.southwest.com/air/flight-schedules/

Hope this helps! :)

Please mark this answer as brainiest!

Thank you! :)

4 0
3 years ago
Other questions:
  • Define the following term: - hue
    11·2 answers
  • Where can you change your web page SafeSearch settings?
    8·1 answer
  • Which function of a web page relies on responsive web design
    14·1 answer
  • What is a algorithm?
    11·2 answers
  • A bluetooth network consists of _____ primary device(s) and up to ____ secondary devices.
    8·1 answer
  • As part of a team, you are assigned to create a financial report. One of your tasks is to put the pieces together as other team
    5·1 answer
  • What is Selection statement?​
    14·2 answers
  • What does playstation network is currently undergoing maintenance?.
    15·1 answer
  • Write algorithm and flowchart for the following<br>a.find the sum and average of any four numbers ​
    9·1 answer
  • _____ allows information to be viewed at a glance without needing to address the individual elements of the information separate
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!