【Python】Statistics

x = 0 #loop variable 
ls = [] #create list
while x == 0: 
shuru = input()
if shuru == '':
x = 1 #interrupt while
else:
ls.append(eval(shuru)) #increase Element
he = 0
#and fangchahe = 0
#variance zhongweishu = 0
#median zhongweils = [] #sorted list
geshu = len(ls) #number of elements
for i in ls:
he += i
pingjun = he / geshu
for j in ls:
fangchahe += pow(2,j-pingjun) #variance = ((the subtraction of each element and the average) squared)/number of elements
fangcha = fangchahe / geshu
zhongweils = sorted(ls) #sorted The function can sort
midgeshu = len(zhongweils)
if midgeshu % 2 == 1:
zhongweishu = zhongweils[midgeshu//2]
else:
zhongweishu = (zhongweils[midgeshu//2]+zhongweils[midgeshu//2 - 1])//2
print(geshu,pingjun,'{0:.3}'.format(fangcha),zhongweishu)
print(zhongweils)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325167041&siteId=291194637