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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started