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
Write a function named dice_eval that accepts two parameters representing numeric dice values and returns a string describing th
Zigmanuir [339]

Following are the "dice_eval" method code into python language.

Program Explanation:

  • Defining a method "dice_eval" that takes two variables "d1,d2" in its parametes.
  • Inside the method, multiple conditional statements were used that adds the parameter values and calculates its value which can be defined as follows:
  • In the if block, it adds the parameters and uses or gate that check its value that is equal to 7 or 11. so, it will return a string message that is 'Winner!'.  
  • In the elif block, it adds the parameters and uses or gate that check its value that is equal to 2 or 3 or 12. so, it will return a string message that is ' C r aps ! '.
  • In the else block, it uses a return keyword that adds parameter value and prints a string value.
  • Outside the method "d1,d2" is declared that inputs the value from the user-end, and passes the value into the method, and prints its value.

Program:

def dice_eval(d1, d2):#defining a method dice_eval that takes two parameters

if (d1+d2)==7 or (d1+d2)==11:#defining if block that adds parameter value and use or operator to check its value

return 'Winner!'#return string value

elif (d1+d2)==2 or (d1+d2)==3 or (d1+d2)==12:#defining elif block that adds parameter value and use or operator to check its value

return 'C r aps!'#return string value

else:#defining else block

return 'Point is '+str(d1+d2)#return string value with adding parameter

d1=int(input())#defining d1 that input value

d2=int(input())#defining d2 that input value

print(dice_eval(d1,d2))#calling method and print its return value

Output:

Please find the attached file

Please find the complete code in the attached file.

Learn more:

brainly.com/question/15011927

4 0
2 years ago
Enrico waited ten years to file a cause of action against Frederico for a breach of contract claim. Frederico can use ______ as
ser-zykov [4K]
Time, due to the amount of time between the initial action and the filing of the report, federico could claim the it didn't happen or something
3 0
3 years ago
Explain how you can compare the size of product to the size of a factor when multiplying fractions without actually doing the mu
777dan777 [17]
You can multiple or dived
4 0
3 years ago
Alan wants to find an image of a car he can use in a presentation. What button should he click in the Images group to run a sear
maksim [4K]

Alan should click on the Clip Art section and then run a search by entering the keyword in the search menu.

A. Clip Art

<u>Explanation:</u>

Alan wants to find an image of a car that he can use in his presentation. It is always a good practice to include pictures and other media like videos, GIFs, and sound effects to make a presentation more engaging and interesting.

In order to include an image, Alan should click on the Clip Art section and then run a search by entering the keyword in the search menu. The clip art allows the user access to the saved images and to the internet for searching the required image.

3 0
3 years ago
Where do you see the future of Information Technology heading?
Oduvanchick [21]

Answer:

Information technology is the process of development and maintenance the computer system components like software for distributing and processing the data in the network.  

The main future aspects of the information technology is to share the data or information in the big networking platform. It basically increase the production of software application in upcoming coming years.  

Information technology term commonly use in computer networks and provide huge applications like internet, telecom equipment and e-commerce.

3 0
3 years ago
Other questions:
  • Which statement regarding hard drives is incorrect?
    8·2 answers
  • What is the purpose of the overload keyword in the ip nat inside source list 1 pool nat_pool overload command?
    8·1 answer
  • Which of these engine components forms a tight seal between the piston and the cylinder and is necessary for proper engine opera
    13·2 answers
  • Jeremy wishes to create a site map for his website. What tag will surround the URL of his home page? A. B. C. D.
    8·1 answer
  • Netflix uses ________ analytics to suggest which movies we should watch as well as to develop new content that it is confident w
    7·1 answer
  • Suppose you own a travel agency in a large city. You have many corporate clients, but growth has slowed somewhat Some long-term
    15·1 answer
  • You manage a network that uses switches. In the lobby of your building, there are three RJ45 ports connected to a switch. You wa
    5·1 answer
  • Suppose that the first goal in a GP problem is to make 3 X1 + 4 X2 approximately equal to 36. Using the deviational variables d1
    15·1 answer
  • Is this statement true or false?
    13·2 answers
  • in Java programming Design a program that will ask the user to enter the number of regular working hours, the regular hourly pay
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!