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
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基础之数据类型
- Lesson02_python3之 基础数据类型
- python 基础数据类型之字符串02
- python 基础2 编码转换 pycharm 配置 运算符 基本数据类型int str list tupple dict for循环 enumerate序列方法 range和xrange
- Python基础4:数据类型:数字 字符串 日期
- python基础(基础数据类型)
- Java入门基础之数据类型的转换、包箱、拆箱(附习题) 个人笔记
- 3-Python3从入门到实战—基础之数据类型(数字-Number)
- Python数据类型 -- 列表习题
- python基础02 基本数据类型
- 一、python基础之数据类型与变量
- python基础---数据类型之间的转换
- Python语法基础(一):变量和数据类型
- python学习之基础数据类型
- Python基础(2) - 动态数据类型
- Python知识点(1)python基础 强制数据类型转换 小总结
- 我与python约个会:09.程序编程基础3~组合数据类型
- 第2章python基础 数据类型与文件操作
- python基础-内置数据类型
- Python基础之数据类型