Functions than return a function

Programe is:
#
# Functions than return a function
#
def function_power(X, NR):
    Y = X
    for i in range(NR):
        Y[i] *= X[i]
    return function_add(Y,NR)
def function_add(X,NR):
    suma = 0
    for i in range(NR):
        suma += X[i]
    return suma
a = [1,2,3,4, 5]
nr = len(a)
b = function_power(a, nr)
print("For list a = ", a,  " the sum of the squares of these elements:  ", b)

Results are:

========== RESTART: /Users/ionivan/Documents/FunctionReturnFunction.py =========
For list a =  [1, 4, 9, 16, 25]  the sum of the squares of these elements:   55


(April 02, 2022)


Comments

Popular posts from this blog

Functions and return parameters list

Functions and many return parameters