前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python比数字游戏

python比数字游戏

作者头像
py3study
发布2020-01-13 12:37:43
5030
发布2020-01-13 12:37:43
举报
文章被收录于专栏:python3python3python3

    今天看到了一个题目,需要输入一个数字,表示成绩和他的成绩的级别:

A: 90--100

B: 80--89

C: 70--79

D: 60--69

E: < 60

    需求在上面大家都看到了,加入输入90-100之间,表示你的级别在A;输入80--89之间,表示你的级别是B;输入的是70--79之间,表示你的级别是C;输入60--69之间,表示你的级别是D;输入小于60,表示你没有通过;

    除了上面的判断之外,我们还需要判断输入的是字符还是数字类型,本来还需要考虑整数和负数的问题,但是由于负数有(负号)-,输入-21之后,系统判断是字符,不是数字类型了,所以这里就不考虑负数了。

     脚本很简单,下面我吧脚本贴上来,感兴趣的童鞋可以看看:

[root@centos6 20130113]# cat aa.py #!/usr/bin/env python print "This script make you input your number \n" print "Then will show your level..." def compare(number):         if number > 100:                 print "Your input is too high"         elif number >=90 and number <= 100:                 print "Your Level is A"         elif number >=80 and number < 90:                 print "Your Level is B"         elif number >=70 and number < 80:                 print "Your Level is C"         elif number >=60 and number < 70:                 print "Your Level is D"         elif number < 60:                 print "You not pass"   def main():     while True:         number=raw_input("Please input your number:")         if number.isdigit():                 Input=int(number)                 print "Your input is ",Input                 compare(Input)                 print "Press Ctrl + C to exit..."         else:                 print "Please input character ..."                 print "Press Ctrl + C to exit..."  main() 

下面来看看运行的效果吧:

[root@centos6 20130113]# ./aa.py This script make you input your number  Then will show your level... Please input your number:100 Your input is  100 Your Level is A Press Ctrl + C to exit... Please input your number:99 Your input is  99 Your Level is A Press Ctrl + C to exit... Please input your number:88 Your input is  88 Your Level is B Press Ctrl + C to exit... Please input your number:77 Your input is  77 Your Level is C Press Ctrl + C to exit... Please input your number:66 Your input is  66 Your Level is D Press Ctrl + C to exit... Please input your number:55 Your input is  55 You not pass Press Ctrl + C to exit... Please input your number:-100 Please input character ... Press Ctrl + C to exit... Please input your number:ijdf Please input character ... Press Ctrl + C to exit... Please input your number: 
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-08-06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档