I'm a total newbie on Python and I would like to calculate the arithmetic average.
a = [int(i) for i in input().split()]
average=sum(a)/len(a)
print('The average is:' ,average)
I'm aware that such code do solve my problems but that is not exactly what I'm looking for.
I want the user to be able to type the number of terms of the arithmetic average and I would like him to be able of typing them separatley on different lines. So I thought the right thing to use was For Loop. I came out with something like this:
n = input('Number of terms')
for i in range (1,int(n)+1):
a=input('Term number '+str(int(i))+': ')
I know that all I need to do know is to find a way to sum all values of a typed on each loop and divide this number by int(n) but I have no idea how to do that.
Can you guys help me with that?
Thanks everyone!
inputreturns a string. Not an integer (or floating point) number. If you're using Python 2 instead, you shouldn't be usinginputbutraw_input.list?