diff --git a/powers of 2.py b/powers of 2.py new file mode 100644 index 0000000..5ac0e09 --- /dev/null +++ b/powers of 2.py @@ -0,0 +1,13 @@ +# 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])