您的位置:首页 > 编程语言 > Python开发

python程序设计基础2:python数据类型习题

2014-03-23 15:37 579 查看
1.输入一个成绩序列,输出各个成绩等级的的人数。数据:score=【45,98,65,87,43,83,68,74,20,75,85,67,79,99】 等级A:(100~90),B(89~80),C(79~70),D(69~60)E(60以下)

2.给定一个成绩单(用字典表示的),找出最大最小值,并求出平均成绩。honest _degree ={'亚伯拉罕':99,‘雅各’:90,‘摩西’:95,‘约书亚’:85,‘约伯’:87,‘彼得’:83,‘西门’:79,‘保罗’:91,‘犹大’:34}

1.代码:

score=[45,98,65,87,43,83,68,74,20,75,85,67,79,99]

A=0

B=0

C=0

D=0

E=0

for s in score:

    if s<60:

        E=E+1

    elif s<70: 

        D=D+1

    elif s<80:

        C=C+1

    elif s<90:

        B=B+1

    else:

        A=A+1

print'______score_____\n'

print '   A=%d'%A

print '   B=%d'%B

print '   C=%d'%C

print '   D=%d'%D

print '   E=%d'%E

print'________________'

        

结果:

______score_____

   A=2

   B=3

   C=3

   D=3

   E=3

________________

2.

代码:

#coding=UTF-8

honest_degree ={'abolahanm ':99,'moxi':90,'yueshuya':95,'job ':85,'peter ':87,'simon ':83,'paul':79,'iselie':91,'judas':34}

maxscore=0

maxname=''

minscore=100

minname=''

avscore=0

num=len(honest_degree)

print'the score is :'

for key in honest_degree.keys():

    print key,honest_degree[key],';'

print'\n'

for key in honest_degree.keys():

    if honest_degree[key]>maxscore:

        maxscore=honest_degree[key]

        maxname=key

    if honest_degree[key]<minscore:

        minscore=honest_degree[key]

        minname=key

    avscore=avscore+honest_degree[key]

avscore=avscore/num

print 'max score is:',maxname,maxscore

print 'min score is:',minname,minscore

print 'mean score is:',avscore

            

结果:

the score is :

judas 34 ;

iselie 91 ;

simon  83 ;

abolahanm  99 ;

yueshuya 95 ;

paul 79 ;

job  85 ;

peter  87 ;

moxi 90 ;

max score is: abolahanm  99

min score is: judas 34

mean score is: 82

    
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python