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编写成绩及格不及格_python小练习:读入一个考试得分,判断这个分数是哪个等级,并输出,考虑异常场景...
读入一个考试得分,判断这个分数是哪个等级,并输出. 等级:>=90 优 ,>=80且小于90 良,>=70 且小于80,中,>=60且<70及格 <60 不及格 覆 ...
- python输入成绩求总分和平均分_python脚本如何输入成绩求平均分?
python脚本如何输入成绩求平均分? python脚本输入成绩求平均分的方法: 脚本要实现功能: 1.输入学生学号: 2.依次输入学生的三门科目成绩: 3.计算该学生的平均成绩,并打印: 4.平均成 ...
- python输入字符a时停止_Python解释器在主提示符或从属提示符后输入中断符( )就会取消当前输入,回到主提示符,会抛出一个KeyboardInterrupt异常。...
[单选题]下列对于字符编码的发展历史节点,正确的是( ). [单选题]Python3解释器执行 not 1 and 1的结果为( ). A. B. C. 0 D. 1 [单选题]Python3解释器执 ...
- python用random函数猜字母_Python小游戏——猜数字教程(random库教程)
今天来开发一个简单的数字逻辑游戏,猜数字(数字炸弹) 首先开发游戏第一件事,了解需求. 猜数字游戏规则: 计算机随机生成一个指定范围的数字,由玩家来猜测, 之后计算机会根据玩家提供数字来与自己生成的数 ...
- python多个判断条件体重_python基础之如何用if语句判断多个条件?
上一篇我们介绍了用if语句判断数字的正数.负数和零.当"判断条件"成立时(非零),则可执行后面的语句.但是多数情况下,仅仅一个判断条件难以满足我们接下来的操作,通常都是多个条件下执 ...
- python输入十个数求最大值_python输入十个数如何输出最大值
python输入十个数输出最大值的方法:1.如果是整数的话,使用函数[a, b, c = map(int, input().split())]:2.使用函数[X=input().split()]. 相 ...
- python输入两个数字输出最大数_Python入门基础实例讲解——两个数字比大小,并输出最大值...
输出:print() print() 方法用于打印输出,最常见的一个函数. 比较运算符 >: 大于,如果运算符前面的值大于后面的值,则返回 True:否则返回 False < :小于,如果 ...
- 安徽省2021年高考各科成绩查询,2021年安徽高考总分是多少 考试科目及各科分数...
2021年安徽高考总分是多少 考试科目及各科分数2021-04-16 08:51:21文/钟诗贺 2021年安徽高考在即,想必很多考生都非常关注安徽高考的总分.考试科目及各科分数.下面小编为大家详细盘 ...
- python百度关键词自动提交订单_Python小工具-根据输入关键字自动打开百度搜索结果的第一页...
PythonBaidu.gif 步骤分析: 1. 伪装浏览器的 User-Agent 2. 读取输入参数并组装为请求参数 3. 使用 `requests` 模块请求数据 4. 使用 `bs4` 查找需 ...
- python输入日期求星期几_python中输入年月日判断星期几?
引入内置模块calendar,输入年.月.日,根据weekday(year,month,day)的返回值,输出该日期是星期几. 函数weekday()返回0-6分别对应星期一至星期日.import c ...
最新文章
- centos7 harbor 单机搭建
- php mysqli还原数据库,PHP mysqli操作数据库
- anything, if you have made a choice
- 如何手写代码进行页面布局
- 计算机磁盘分为硬盘和什么,fat32是什么?
- scrapy保存、中断、继续执行爬虫程序
- 天天在用Redis,那你对Redis的AOF持久化到底了解多少呢?
- mysql 去除重复 Select中DISTINCT关键字的用法(查询两列,只去掉重复的一列)
- POJ 2287 田忌赛马 贪心算法
- 数据结构与算法-进阶(十二)最短路径Dijkstra 算法
- YOLOv3 SPP源码分析
- 【论文笔记】Contextual Diversity for Active Learning(ECCV2020)
- linux中错误无法解析域名无法下载,Linux无法解析域名的解决办法
- Android 3D模型展示
- html5 设备管理信息 device
- 减少计算机视觉效果可以减少游戏卡顿吗,Win10玩游戏更流畅的几招优化方法(亲测有效)...
- SecurityConfig+TokenConfig+Oauth2Config--CureGuy
- 【冰糖R语言】Shiny简单笔记
- OmniPeek11安装 (驱动安装)
- 保险IT从业者必须知道 的健康险