The Power of While Loops

Use a while loop to complete the function feel_the_power so that it takes the initial_number and multiplies it by itself power number of times.

Examples:

>>> feel_the_power(3, 0)
1

>>> feel_the_power(3, 1)
3

>>> feel_the_power(3, 2)
9

>>> feel_the_power(3, 3)
27

Hint: You'll need additional variables to keep track of both the result and how many times you've multiplied it by itself.

Hint 2: Remember, with multiplication, you start your result at 1 instead of 0 because if you multiply by 0 you get 0.

Hint 3: NO INFINITE LOOPS!

Test Cases

test while loop power zero - Run Test

def test_while_loop_power_zero():
    assert feel_the_power(3, 0) == 1

test while loop power one - Run Test

def test_while_loop_power_one():
    assert feel_the_power(3, 1) == 3

test while loop power three - Run Test

def test_while_loop_power_three():
    assert feel_the_power(3, 3) == 27

Solution 1

def feel_the_power(initial_number, power):
    result = 1
    power_count = 0
    while power_count < power:
        result *= initial_number
        power_count += 1
    return result
def feel_the_power(initial_number, power): pass