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]
4 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]4 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
Question
LuckyWell [14K]

Answer:

you go to the what ever you use for the stuff i thing you want

Explanation:

6 0
3 years ago
The most common approach for making individual analysis is to:
stiks02 [169]

Answer:

A)predict future organizational needs.

Explanation:

It is important to perform a SWOT analysis. Which helps us predict future business needs. Highlighting strengths, weaknesses, opportunities and threats.

  1. analyzing its internal characteristics (Weaknesses and Strengths).
  2. external situation (Threats and Opportunities) in a square matrix.
8 0
3 years ago
B. Identify the purpose of each of the following types of utility programs
olya-2409 [2.1K]

<u>These are the types </u>:

1. Antivirus software : Detects and removes virus and malwares from   computer system.

2.Disk defragmenter : Reduces the fragmented space in the disk.

3.Disk cleaner : Build to find and delete unwanted files to free the disk space.

6 0
4 years ago
Will mark brainliest! What does this code do? What kind of code is this called?
gavmur [86]

Answer:

lol u can barly call this a code

Explanation:

its just a type error code i think

3 0
3 years ago
What can be controlled through IoT? Choose four answers.
BaLLatris [955]

Answer:

Door locks

Light switches

Security cameras

Thermostat

Explanation:

IoT is internet of things that means network of different things that are interconnected through internet and make the decision with the help of Electronic sensors. The sensor sense the data from environment at different times and send this to the cloud (that may be the server). On the basis of this data different devices such as door looks, light switches, security cameras and thermostat take decisions with the help of controllers and change their current state.

<u>For Example</u>

In case of door look, there may be sensor that is sensing the finger prints of the user and after recognizing the person the door will be unlock. If unauthenticated user will try to open the lock a message has been sent to concerned. The training data of the the authorized persons is saved on the cloud, whenever someone tries to access, the data from sensor and cloud send to controller for making comparison and decision. So we can say that Door lock can be controlled IoT.

In case of light switches, there are few sensor available to sense the intensity of life. Different training values of that sensors are stored on the cloud. Whenever these sensors sense the light intensity, they send the data to the cloud contentiously, whenever the data match with darkness intensity, a signal has been send from controller to the switch to ON the lights.

Same as in cameras and Thermostat both are sending data to the cloud and controller. With the help of different image processing techniques and sensor camera will take the decision related to face recognition. Thermostat devices are also on and off by variation of temperature.

7 0
4 years ago
Other questions:
  • Describe the difference between public and private IPv4 addresses. If a network is using private IP addresses, how can the compu
    13·1 answer
  • We use a cubic equation in which the variables and coefficients all take on values in the set of integers from 0 through p - 1 a
    8·1 answer
  • Benching system are prohibited in
    5·1 answer
  • Anybody know this question???
    6·1 answer
  • A customer uses an app to order pizza for delivery. Which component includes aspects of the customer's interaction with an enter
    10·1 answer
  • Joshua always participate in team meetings and comes up with ideas and suggestions. what quality is he demonstrating?
    7·1 answer
  • Decimal numbers is equivalent to binary 110
    5·1 answer
  • Advantages of python programming language
    10·1 answer
  • Write a code segment that will store a dinner selection in option1 based on the values of rsvp and selection. The intended behav
    5·1 answer
  • Which is the base class in the following statement? class car : public vehicle
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!