Display Powers of 2 Upto N Numbers in Python

(Last Updated On: 16/11/2022)

In this program, you’ll learn to display the powers of 2 up to n numbers in python using for loop.

Python Program to Display Powers of 2 Upto N Numbers

# Display Powers of 2 Upto N numbers in python

# we are taking a number from user as input
# entered value will be converted to int from string
total_terms = int(input("Enter the Total Number of Terms: "))

for i in range(total_terms):
	print("2 raised to the power ", i, " is ", 2 ** i)

Output:

Enter the Total Number of Terms: 10
2 raised to the power  0  is  1
2 raised to the power  1  is  2
2 raised to the power  2  is  4
2 raised to the power  3  is  8
2 raised to the power  4  is  16
2 raised to the power  5  is  32
2 raised to the power  6  is  64
2 raised to the power  7  is  128
2 raised to the power  8  is  256
2 raised to the power  9  is  512

Leave a Reply

Your email address will not be published. Required fields are marked *