Exponents || Python || challenge
In this challenge, we will be using nested loops in order to raise a list of numbers to the power of a list of other numbers. What this means is that for every number in the first list, we will raise that number to the power of every number in the second list. If you provide the first list with 2 elements and the second list with 3 numbers, then there will be 6 final answers. Let’s look at the steps we need:
Challenge code:
Create a function named?exponents()?that takes two lists as parameters named?bases?and?powers. Return a new list containing every number in bases?raised?to every number in?powers.
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.
The solution: