To display powers of 2 in python, you have to ask from user to enter upto how many terms he/she want to print the powers of two, and then print powers of 2 upto the given term as output as shown in the program given here.
Following python program ask from user to enter limit to display powers of 2 upto the given limit:
# Python Program - Display Powers of 2 while True: print("Enter 'x' for exit.") limit = input("Upto how many terms ? ") if limit == 'x': break else: term = int(limit) res = list(map(lambda x: 2 ** x, range(term))) for i in range(term): print("2 raised to the power",i,"=",res[i]) print("\n")
Here is the sample run of the above Python program to illustrate how to find and print powers of 2: