Write a program to Display Powers of 2 Using Anonymous Function in Python
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# Python Program to display the powers of 2 using anonymous function #to take number of terms from user terms = int(input("How many terms? ")) # use anonymous function result = list(map(lambda x: 2 ** x, range(terms))) # display the result print("The total terms is:",terms) for i in range(terms): print("2 raised to power",i,"is",result[i]) |