loops - Simple arithmetic average in Python -


i'm total newbie on python , calculate arithmetic average.

a = [int(i) in input().split()]  average=sum(a)/len(a)  print('the average is:' ,average) 

i'm aware such code solve problems not i'm looking for.

i want user able type number of terms of arithmetic average , him able of typing them separatley on different lines. thought right thing use loop. came out this:

n = input('number of terms')  in range (1,int(n)+1):      a=input('term number '+str(int(i))+': ') 

i know need know find way sum values of typed on each loop , divide number int(n) have no idea how that.

can guys me that?

thanks everyone!

n = input('number of terms') acc = 0 in range(1,int(n)+1):     a=input('term number '+str(int(i))+': ')     acc += float(a) print('the average ',acc/int(n)) 

the idea create accumulator variable acc entered numbers added. after loop acc equal sum of numbers entered. divide number of terms , arithmetic average.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -