python编写成绩及格不及格_python小练习:读入一个考试得分,判断这个分数是哪个等级,并输出,考虑异常场景...
读入一个考试得分,判断这个分数是哪个等级,并输出。
等级:》=90 优 ,>=80且小于90 良,》=70 且小于80,中,》=60且<70及格
《60 不及格
覆盖场景:
考虑字符类型(str,float)
数字范围(0-100)以外的
小数98.99等
代码:
#encoding=utf-8
while True:
try:
score = raw_input("input the score,'exit' to stop: >>:")
#print type(score)
#print isinstance(score,str)
if "exit" in score:
break
else:
score = float(score)
print "score:",score
if score >= 90 and score <=100:
print u"优"
elif score>=80 and score <90:
print u"良"
elif score >=70 and score <80:
print u"中"
elif score >= 60 and score <70:
print u"及格"
elif score >=0 and score <60:
print u"不及格"
else:
print u"请重新输入!"
except Exception,e:
print e
print u"请重新输入!"
continue
结果:
D:\>python test.py
input the score,'exit' to stop: >>:90
score: 90.0
优
input the score,'exit' to stop: >>:100
score: 100.0
优
input the score,'exit' to stop: >>:89
score: 89.0
良
input the score,'exit' to stop: >>:78
score: 78.0
中
input the score,'exit' to stop: >>:67
score: 67.0
及格
input the score,'exit' to stop: >>:56
score: 56.0
不及格
input the score,'exit' to stop: >>:1
score: 1.0
不及格
input the score,'exit' to stop: >>:0
score: 0.0
不及格
input the score,'exit' to stop: >>:-2
score: -2.0
请重新输入!
input the score,'exit' to stop: >>:9.3
score: 9.3
不及格
input the score,'exit' to stop: >>:8.88
score: 8.88
不及格
input the score,'exit' to stop: >>:90.89
score: 90.89
优
input the score,'exit' to stop: >>:101
score: 101.0
请重新输入!
input the score,'exit' to stop: >>:200
score: 200.0
请重新输入!
input the score,'exit' to stop: >>:stop
could not convert string to float: stop
请重新输入!
input the score,'exit' to stop: >>:sdlfj
could not convert string to float: sdlfj
请重新输入!
input the score,'exit' to stop: >>:*&%$
could not convert string to float: *&%$
请重新输入!
input the score,'exit' to stop: >>:exit
python编写成绩及格不及格_python小练习:读入一个考试得分,判断这个分数是哪个等级,并输出,考虑异常场景...相关推荐
- python爬虫requests简单案例_Python小例子:一个最简单的爬虫
学习编程的过程中总是有些枯燥.成天面对黑乎乎的窗口可能真的有些无聊.来,我们做点好玩的事情吧.比如 将网络上你喜欢的图片保存下来.不过千里之行 始于足下,在学习将网页上的图片下载下来之前.我们首先要学 ...
- python计算一元二次_Python小程序-写一个计算一元二次方程的程序函数
题目要求: 请定义一个函数quadratic(a, b, c),接收3个参数,返回一元二次方程:ax^2 + bx + c = 0的两个解. 程序代码: 这只是一个函数,如果你不调用它的话,是不会产生 ...
- python回到本次循环开头_Python中,当一个while循环判断为false,结束这个循环的时候,怎么进入到下一个循环中?...
根据题主对问题的描述,题主需要的答案也许是关于 while 循环结构,Continue 和 Break 的详细解释.了解了循环的控制后,题主便能很清楚地明白自己需要如何控制循环来达到想要的答案了. 先 ...
- python编写函数 avg(lst),参数 lst 是一个列表。函数可以返回 lst 的整数平均值,调用 avg(lst) 函数求每个学生的平均成绩。
python编写函数 avg(lst),参数 lst 是一个列表.函数可以返回 lst 的整数平均值,调用 avg(lst) 函数求每个学生的平均成绩. 已知成绩列表 s={'小李':[77,54], ...
- 利用条件函数判断计算机这课成绩及格情况,如何用Excel表格中的if函数来判断成绩及格不及格...
如何用Excel表格中的if函数来判断成绩及格不及格 腾讯视频/爱奇艺/优酷/外卖 充值4折起 今天给大家介绍一下如何用Excel表格中的if函数来判断成绩及格不及格的具体操作步骤. 1. 打开电脑后 ...
- 编写python程序、计算账户余额_小明有20w存款存在余额宝中,按余额宝年收益为3.35%计算,用Python编写程序计算,多少年后小明的存款达到30w?...
[判断题]卤素灯泡是在灯泡内充入氟.氯等卤素气体. [单选题]我国刑法第12条关于溯及力的规定采取的是( ). [填空题]本地局域网 LAN 内, () 和无绳电话速率较低,主流带宽是 100kbps ...
- C++primer第五版 编写一段程序,读入一个包含标点符号的字符串,将标点符号去除后输出字符串剩余的部分
这是一个关于字符串处理的简单程序,但是里面有一些细节是值得关注的.先附上程序: // primer_3_2_3.cpp : Defines the entry point for the applic ...
- python编写猜大小游戏_python编写猜数字小游戏
本文实例为大家分享了python编写猜数字小游戏的具体代码,供大家参考,具体内容如下 import random secret = random.randint(1,30) guess = 0 tri ...
- python 成绩分析系统_用Python编写成绩管理分析系统(故事升级版)
目录 项目总览 生活小故事引入 项目思路 项目实现 功能改善 代码展示 效果演示 项目后期 项目适用 每文一语 项目总览 生活小故事引入 微风和煦,散乱在办公桌上的测验小试卷还有几分"热度& ...
最新文章
- Java中的两个关键字——super、this
- 将base64编码图片上传到七牛云
- 长征五号复飞成功:史上最重最大,2020月岩采样火星探测都要靠它
- wamp2.5 64 mysql_Wamp2.5 64bit,无法修改MySQL datadir位置_MySQL
- 2-2 Time类的定义_JAVA
- linux 构建 无线网络 过程
- C#中POST数据和接收的几种方式
- python初始化方法对应的变量是全局变量嘛_在Python中初始化全局变量的正确方法...
- swift基础学习(八)
- Cookie、Session、Token
- 【w3cschool】PHP语法简单复习
- Nacos教程_3 整合SpringCloud(配置中心+服务发现)
- 排序算法专题-堆排序
- vue脚手架安装 axios 安装 配置 轮播图
- 莫烦 Python 基础
- 计算机有关英语单词以及谐音,英语单词中文谐音大全
- 各种标点符号的英文怎么念
- 人工智能之Python人脸对比、人脸检测
- ASP.NET c# 实验日记(1)
- 《大道至简》的幕后故事(3):“愚公移山记”事物篇
热门文章
- CM: 使用ICF node实现对附件的读取
- 打印出系统所有即未被assign到business transaction和IBASE component的product ID列表
- SAP CRM WebClient UI,点击Master Data工作中心后执行的JavaScript代码
- SAP CRM WebClient UI cross workcenter的context cleanup
- 已知ABAP tcode,需要查找assign了该tcode的PFCG role
- SAP WebClient UI view controller所有可用的属性列表
- 打开windows 10系统语言设置的快捷方式
- php代码执行相关函数,关于当前PHP脚本运行时系统信息相关函数
- 0基础改行学python_零基础想转行学习python,该如何学习,有学习路线分享吗?...
- 中求解数组中元素个数_JavaScript之学underscore在数组中查找指定元素