读入一个考试得分,判断这个分数是哪个等级,并输出。

等级:》=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小练习:读入一个考试得分,判断这个分数是哪个等级,并输出,考虑异常场景的更多相关文章

  1. python小练习:使用循环和函数实现一个摇骰子小游戏。游戏规则如下:游戏开始,首先玩家选择Big or Small(押大小),选择完成后开始摇三个骰子,计算总值,11<=总值<=18为“大”,3<=总值<=10为“小”。然后告诉玩家猜对或者是猜错的结果。

    python小练习:使用循环和函数实现一个摇骰子小游戏.游戏规则如下:游戏开始,首先玩家选择Big or Small(押大小),选择完成后开始摇三个骰子,计算总值,11<=总值<=18为“ ...

  2. python小练习1:设计这样一个函数,在桌面的文件夹上创建10个文本,以数字给它们命名。

    python小练习1:设计这样一个函数,在桌面的文件夹上创建10个文本,以数字给它们命名. 使用for循环即可实现: for name in range(1,11): desktop_path='C: ...

  3. Day1:第一个python小程序

    Day1:第一个python小程序与开发工具Pycharm 一.Hello World C:\Users\wenxh>python Python 3.6.2 (v3.6.2:5fd33b5, J ...

  4. 第一个python小脚本

    第一个python小实验 前言 作为一个工作1年的linux运维搬砖师来说,发现没点开发能力真的是不好混啊.于是下定决心学习python! 直接上刚写的语句(大神莫鄙视) 通过控制台输入一个账号密码, ...

  5. python 一个二维数组和一个整数,判断数组中是否含有该整数

    在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序. 请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. de ...

  6. Python基础(一):程序输入输出、判断合法用户、编写判断成绩的程序

    一.程序输入输出 目标: 编写login.py脚本,实现以下目标: 提示用户输入用户名 将用户名保存在变量中 在屏幕上显示欢迎用户的信息 方案: 编写程序时,很多情况下都需要程序与用户交互.在pyth ...

  7. Python小游戏、小程序

    python 小游戏之摇骰子猜大小 python 实现一个双色球生成程序 python-循环与判断练习题

  8. Python小项目之五子棋

    1.项目简介 在刚刚学习完python套接字的时候做的一个五子棋小游戏,可以在局域网内双人对战,也可以和电脑对战 2.实现思路 局域网对战 对于局域网功能来说,首先建立连接(tcp),然后每次下棋时将 ...

  9. python小技巧 小知识

    python小技巧 小知识 python系统变量(修改调用shell命令路径)或用户空间说明 20150418 python调用系统命令,报找不到.怎么办? 类似执行shell的: [ -f /etc ...

随机推荐

  1. 关于ios下字体描边的一个细节

    转载请注明,来自:http://blog.csdn.net/skyman_2001    CGContextSetTextDrawingMode(context, kCGTextStroke);    ...

  2. 搭建nginx服务器,虚拟主机,反向代理

    1 搭建Nginx服务器 1.1 问题 在IP地址为192.168.10. 5的主机上安装部署Nginx服务,并可以将Nginx服务器升级到更高版本,要求编译时启用如下功能: SSL加密功能 查看服务 ...

  3. MySQL 8.0.11 报错[ERROR] [MY-011087] Different lower_case_table_names settings for server ('1')

    --报错信息: 2018-06-07T19:52:26.943083+08:00 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld ...

  4. 安装与破解PyCharm专业版

    安装与破解PyCharm专业版(有两种方法) 一.安装与破解PyCharm专业版 1.安装pycharm(建议安装python3) 这是网址:(https://www.jetbrains.com/py ...

  5. LeetCode之有效括号

    class Solution:    def isValid(self,s):         #第一步,if 判断传入为空的情况        if s == "":      ...

  6. vue.js-moment的使用

    1.安装: npm install moment --save 2.引入:import moment from 'moment.js' 3.moment("时间").format( ...

  7. 死锁与递归锁 信号量 event 线程queue

    1.死锁现象与递归锁 死锁:是指两个或两个以上的进程或线程在执行过程中,因争抢资源而造成的一种互相等待的现象,若无外力作用,它们都将无法推进下去,此时称系统处于死锁状态或系统产生了死锁,这些永远在互相 ...

  8. 微信小程序https发起请求失败的解决方法

    https://blog.csdn.net/yuhui123999/article/details/60572888 https://blog.csdn.net/yuhui123999/article ...

  9. 【开发者笔记】python中的类方法(@classmethod)和静态方法(@staticmethod)

    在java.c#等高级语言中我们用static来定义静态方法和静态变量,那么在python中如何定义静态方法和静态变量呢. python提供了@classmethod和@staticmethod来定义 ...

  10. [LeetCode] 872. Leaf-Similar Trees_Easy tag: DFS

    Consider all the leaves of a binary tree.  From left to right order, the values of those leaves form ...