I’m trying to perform exponentiation with values inside a nested list. I think my main issue is understanding how parameters work with nested lists and if they act as two separate entities or if I need to assign them to new variables.
Create a function named
exponents()
that takes two lists as parameters namedbases
andpowers
. Return a new list containing every number in basesraised
to every number inpowers
.For example, consider the following code.
exponents([2, 3, 4], [1, 2, 3])
the result would be the list
[2, 4, 8, 3, 9, 27, 4, 16, 64]
. It would first add two to the first. Then two to the second. Then two to the third, and so on.
Here is my code. I feel like I’m close but my equation seems to cause the function to go out of range.
At it’s core I know I have to do
bases ** power
#Write your function here
def exponents(bases, powers):
new_lst = []
for base in range(0, len(bases)):
for power in powers:
#print(bases[base])
#print(powers[power])
value = bases[base] ** powers[power]
new_lst.append(value)
return new_lst
return new_lst
#bases ** powers
#Uncomment the line below when your function is done
print(exponents([2, 3, 4], [1, 2, 3]))