In: Computer Science
############callbacks
##def function_1( x ) : return x ** 2
##def function_2( x ) : return x ** 3
##def function_3( x ) : return x ** 4
##
###### create a list of callbacks to each of the functions
######by referencing their names
##
##callbacks = [ function_1 , function_2 , function_3 ]
##
######display a heading and the result of passing a value to each
of the
######named functions:
##
##print( '\nNamed Functions:' )
##for function in callbacks : print( 'Result:' , function( 3 )
)
##
####Task 3. Run the code above. Understand it. Display callback
for
####the situation when you need to run 2*function_1,
2*function_2,2*function_3,
####for x = 10, show that your code works.
#source code:
import dis
def function_1(x):
return x**2
def function_2(x):
return x**3
def function_3(x):
return x**4
callbacks=[function_1,function_2,function_3] #callback
fucntions
x=[3,6,8] #for passing values purpose
for i in range(len(callbacks)): #iterate lenght of list 3
print("Result:,function({})={}".format(x[i],callbacks[i](x[i])))
#pass each value to the function and print the output
for i in range(len(callbacks)):
print("Result:,function({})={}".format(10,2*callbacks[i](10)))
#pass the 10 for each function and print the output
#output:
#if you have any doubts comment below.