Use a for loop and the list append method to generate the powers of 2 to produce the following result [1, 2, 4, 8, 16, 32, 64, 128]
n=8
power_list=[]
for i in range(0,n):
power_list.append(2**i)
print(power_list)
Output:
[1, 2, 4, 8, 16, 32, 64, 128]
Comments
Leave a comment