亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

python里對list中的整數(shù)求平均并排序

 更新時間:2014年09月12日 10:55:26   投稿:hebedich  
本文主要記述了使用Python將list重點整數(shù)求平均值之后在進行排列的過程,并把代碼分享給大家,希望大家能給鼓鼓掌~~~

問題

定義一個int型的一維數(shù)組,包含40個元素,用來存儲每個學員的成績,循環(huán)產(chǎn)生40個0~100之間的隨機整數(shù),
(1)將它們存儲到一維數(shù)組中,然后統(tǒng)計成績低于平均分的學員的人數(shù),并輸出出來。
(2)將這40個成績按照從高到低的順序輸出出來。

解決(python)

#! /usr/bin python
#coding:utf-8


from __future__ import division   #實現(xiàn)精確的除法,例如4/3=1.333333
import random

def make_score(num):
  score = [random.randint(0,100) for i in range(num)]
  return score

def less_average(score):
  num = len(score)
  sum_score = sum(score)
  ave_num = sum_score/num
  less_ave = [i for i in score if i<ave_num]
  return len(less_ave)

if __name__=="__main__":
  score = make_score(40)
  print "the number of less average is:",less_average(score)
  print "the every socre is[from big to small]:",sorted(score,reverse=True)

相關文章

最新評論