Question: How can i get this to run properly. def get_total(a, b): #enclosed variable declared inside a function total = a + b def double_it(): #local

How can i get this to run properly.

def get_total(a, b):

#enclosed variable declared inside a function

total = a + b

def double_it():

#local variable

double = total * 2

print(double)

double_it()

#double variable will not be accessible

print(double)

return total

---------------------------------------------------------------

I had posted this exact question earlier and the person who answered wrote this below with NO indentations and python will not run that long code like that. Please write answer correctly in python format

Here's the revised code with these changes applied:

def get_total(a, b): # enclosed variable declared inside a function total = a + b def double_it(): # local variable double = total * 2 return double # call double_it() function double = double_it() # return double variable return double # call get_total() function with a=2 and b=2 result = get_total(2, 2) print(result)

This should print 8 when you call the get_total() function with a=2 and b=2.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!