Solution 1

def powers_of_2(power):
    result = 1
    for num in range(power):
        result *= 2
    return result

Powers of 2

You've done something similar to this with a while loop, now do it with a for loop! You'll have to use the range() function.

Complete powers_of_2 using a for loop so that receives the power and returns 2 to that power.

Examples:

>>> powers_of_2(0)
1

>>> powers_of_2(1)
2

>>> powers_of_2(2)
4

>>> powers_of_2(3)
8

Test Cases

test powers of 2 - Run Test

def test_powers_of_2():
    assert powers_of_2(3) == 8
    assert powers_of_2(1) == 2
    assert powers_of_2(0) == 1
def powers_of_2(power): pass