In [2]:
sum([x*x for x in range(10)]) # Source - PEP - 289
Out[2]:
In [3]:
#So whats -> x in range(10):
for x in range(10): # as seen below the variable - x , will take all values from 0-9
print(x)
In [5]:
mylist = [] # Init empty list
for x in range(10):
mylist.append(x) # Append all ints from 0-9
In [8]:
# Multiply Consecutive Elements of LIST - mylist
#
print("myList = ",mylist)
n = 2
sqr_of_nums = []
for e in range(len(mylist)):
sqr_of_nums.append(mylist[e]*mylist[e])
print("List of Product's of Consecutive Nums = ",sqr_of_nums)
print("SUM of Product's of Consecutive Nums = ",sum(sqr_of_nums))
In [ ]:
No comments:
Post a Comment