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
When computers connect to one another to share information, but are not dependent on each other to work, they are connected thro
Andrej [43]
Peer-to-peer would be my best bet. Hope this helps. 
3 0
3 years ago
Read 2 more answers
You use a cisco 2900 router in your network. you are considering purchasing and implementing the Unifield communications feature
Olenka [21]

Explanation:

License boot module c2900, technology-package uck9

7 0
3 years ago
It is good practice, however, for policy _________________________ to solicit input both from technically adept information secu
s2008m [1.1K]

Answer:

It is good practice, however, for policy <u>Administrator </u>to solicit input both from technically adept information security experts and from business-focused managers in each community of interest when making revisions to security policies.

<u>Explanation</u>

Administrator is the person who has access to each part of the computer. Ha has rights to revise, add or edit application. The administrator is authorized to make and implement policies that are for the interest of the community.

7 0
3 years ago
A direct-mapped cache holds 64KB of useful data (not including tag or control bits). Assuming that the block size is 32-byte and
Cerrena [4.2K]

Answer:

A) Number of bits for byte = 6 bits

B) number of bits for index = 17 bits

C) number of bits for tag = 15 bits

Explanation:

Given data :

cache size = 64 kB

block size = 32 -byte

block address = 32 -bit

number of blocks in cache memory  

cache size / block size = 64 kb / 32 b = 2^11 hence the number of blocks in cache memory = 11 bits = block offset

A) Number of bits for byte

log _{2} (6)^2 = 6  bits

B) number of bits for index

block offset + byte number

= 11 + 6 = 17 bits

c ) number of bits for tag

= 32 - number of bits for index

= 32 - 17 = 15 bits

5 0
3 years ago
You decide to buy some stocks for a certain price and then sell them at another price. Write a program that determines whether o
ser-zykov [4K]

Answer:

#here is code in python.

#read number of shares

num_share = int(input("Enter number of shares:"))

#read purchase price

buy_p = float(input("Enter purchase price:"))

#read sell price

sell_p = float(input("Enter sale price:"))

#total buying cost

buy_cost=buy_p*1.03*num_share

#total selling cost

sell_cost=sell_p*0.97*num_share

#if net profit

if(sell_cost>buy_cost):

   print("After the transaction, you made " +str(sell_cost-buy_cost)+ " dollars.")

#if net loss

else:

   print("After the transaction, you lost " +str(buy_cost-sell_cost)+ " dollars.")

Explanation:

Read the total number of shares from user.Then read buying price of a share and selling price of a share.Then calculate total buying cost including commission.Calculate total selling cost excluding the commission.If total buying cost is greater than total selling cost the print the profit else print the loss in the transaction.

Output:

Enter number of shares:10

Enter purchase price:10

Enter sale price:10

After the transaction, you lost 6.0 dollars.

4 0
3 years ago
Other questions:
  • What is computer ????
    11·1 answer
  • Why is it more important now than ever before to know how to evaluate websites and other online sources of information?
    7·1 answer
  • You are troubleshooting an interface issue on your cisco ios isr. the output of "show ip interface brief" indicates that etherne
    11·1 answer
  • Identify the mobile device deployment option that gives the user flexibility to select a device, but allows the company to contr
    5·1 answer
  • I don't know the answer and I tried different ones and they not what the book is looking for.
    7·1 answer
  • Why is the database management systems (dbms the heart of the database functionality?
    6·2 answers
  • What methods would you add to make this class declarationvery useful?
    11·2 answers
  • (TCO B) The symbol shown as a three-sided box that is connected to the step it references by a dashed line is what?
    12·1 answer
  • Which is a concept of the CIA of Computer Security
    7·1 answer
  • True or false The List interface defines a collection for storing elements in a sequential order.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!