Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3) Write a JavaScript script that has subprograms nested three deep and in which

ID: 3784646 • Letter: 3

Question

3) Write a JavaScript script that has subprograms nested three deep and in which each nested subprogram references variables defined in all of its enclosing subprograms.

4) Repeat Programming Exercise 3 with Python.

I ONLY NEED #4 awnsered, number 3 is just for REFERENCE,

below is my start of what i've done

working python code compiled on ideone

# your code goes here
# your code goes here
def sub1():
   print"Hello"
def sub2():
   sub1()
   print"Inside sub 2"
def sub3():
   sub2()
   print "Inside sub 3"
sub3()  

Explanation / Answer

Ans. You just have to pass the variables as arguments to the functions. Here is the working code. var3 is referenced by sub2 and var2 is referenced by sub1.

def sub1(var2):
print var2
print"Hello"
def sub2(var3):
var2 = 3
sub1(var2)
print var3
print"Inside sub 2"
def sub3():
var3 = 4
sub2(var3)
print "Inside sub 3"   
sub3()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote