Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Python Program to Display Powers of 2 Using Anonymous Function

# Display the powers of 2 using anonymous function

terms = 10

# Uncomment code below to take input from the user
# terms = int(input("How many terms? "))

# use anonymous function
result = list(map(lambda x: 2 ** x, range(terms)))

print("The total terms are:",terms)
for i in range(terms):
   print("2 raised to power",i,"is",result[i])
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #Python #Program #Display #Powers #Using #Anonymous #Function
ADD COMMENT
Topic
Name
8+3 =