Display Powers of 2 Using Normal Function in Python

(Last Updated On: 18/11/2022)

Python Program to Display Powers of 2 Using Normal Function

# Display Powers of 2 using Normal Function in python

# function receives a value as its argument & returns 2 raised to the power of the value.
def Func(x):
	return 2 ** x

# 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: "))

print()
for i in range(total_terms):
	print("2 raised to the power ", i, " is ", Func(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 *