I\'m working on a practice problem in Python. I\'m calculating and listing all t
ID: 3830849 • Letter: I
Question
I'm working on a practice problem in Python. I'm calculating and listing all the powers of 5, between 0 and going up to 5, which I've got working, and gives me a list of each from 1-625.
What I'm having trouble with is finding out how to find the average and sum of the the powers (1, 5, 25, 125, 625). How would I write the code for this, and where would I put it within the program? Any help would be appreciated.
... also, would there be another way of writing this, without using the 'lambda' function?
exp = 5
pwrcount = list(map(lambda x: 5 ** x, range(exp)))
print ('Number of exponents is: ',exp)
for n in range(exp):
print ('5 raised to the power of',n,'is',pwrcount[n])
Explanation / Answer
from __future__ import division
exp = 5
pwrcount = [exp**i for i in range(0, exp)]
for n in range(exp):
print ('5 raised to the power of',n,'is',pwrcount[n])
avg = sum(pwrcount)/len(pwrcount)
print("average and sum of the the powers: " + str(avg))
# code link: https://paste.ee/p/gk5pA
Changed your code as well to not use lambda