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
Plz answer all the questions :)
AURORKA [14]

Answer:

is there multiple choice or do i have to answer from my own words??

7 0
4 years ago
Richard owns a chain of hardware stores. He wants to update the store website and write a numbered list of all the items in his
Digiron [165]
Use ordered list
  1. tag and put each item inside of a list item
  2. tag.
8 0
3 years ago
Read 2 more answers
How to get the pc accelerate pro virus off my computer
garik1379 [7]
Try to see a computer specialist to help
4 0
3 years ago
Read 2 more answers
Graphics you can select to reinforce the goal of your document include ____.
Tanya [424]
The answer would be D all of the above.
8 0
3 years ago
Using cell references, enter a formula in cell b6 to calculate monthly payments for the loan described in this worksheet. omit t
olga55 [171]

Answer:

On the Formulas tab, in the Function Library group, click the Financial button, and click PMT. Enter B3/12 in the Rate argument box. Enter B4 in the Nper argument box. Enter B2 in the Pv argument box. Click OK.

Explanation:

Inside any excel spreadsheet like Microsoft Excel or Libre office Calc.

While your cursor is present at cell B6, do the following

On the formulas tab, in the function library group,

click the financial button

Then click PMT

Enter B3/12 in the rate argument box.

Enter b4 in the Nper argument box. Enter B2 in the argument box.

Click ok.

The following assumptions were made:

the annual interest rate is stored in cell B3

the number of payments in cell B4

the loan amount in cell B2.

8 0
4 years ago
Other questions:
  • You can drag a cell to a new location by pointing to the cell border until the pointer displays a _______ arrow, and then draggi
    9·2 answers
  • Acrynom for wys or wyg
    10·1 answer
  • Mention five features of word processing application​
    10·1 answer
  • Which forensics tool would you use to reveal recent pages viewed via the internet explorer browser?
    10·1 answer
  • Define and test a function myRange. This function should behave like Python’s standard range function, with the required and opt
    13·2 answers
  • What is the system of phonographic disc recordings paired with a projector called?
    9·1 answer
  • How to make a water bottle rocket??
    6·1 answer
  • I need help with workplace safety systems please help
    10·1 answer
  • How to automatically ccleaner smartphone?
    10·1 answer
  • Being a part of an organization or giving back to the community is which rewards of work factor?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!