Question: Python Using the following functions, create a power_sum_list that accepts an integer list as the first argument and an integer as the second argument. Have

Python Using the following functions, create a power_sum_list that accepts an integer list as the first argument and an integer as the second argument. Have the function return the sum of the integers in the list when each element is raised to the power of the second argument.

#1 SUM

#function

def sum_int_list(t_list):

s=0

#for each element in list

for i in range (0,len(t_list)):

#calculating sum of elements in the list

s= s + t_list[i]

#returning sum

return s

#driven input

t_list = [4, 6, 6]

test_list = t_list

result = sum_int_list(test_list)

print(result)

#2 POWER

#function

def power_int_list(test_list,power):

result_pow=[]#return list

for i in test_list:#for each element

result=1

#multiplying with that number and appending to result

for j in range(power):

result*=i

result_pow.append(result)#appending the result

return result_pow#returning result

test_list=[5,3,2]#first argument

print(power_int_list(test_list,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!