python比数字游戏

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

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之后,系统判断是字符,不是数字类型了,所以这里就不考虑负数了。

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

 

 
 
  1. [root@centos6 20130113]# cat aa.py 
  2. #!/usr/bin/env python 
  3. print "This script make you input your number \n" 
  4. print "Then will show your level..." 
  5. def compare(number): 
  6.         if number > 100
  7.                 print "Your input is too high" 
  8.         elif number >=90 and number <= 100
  9.                 print "Your Level is A" 
  10.         elif number >=80 and number < 90
  11.                 print "Your Level is B" 
  12.         elif number >=70 and number < 80
  13.                 print "Your Level is C" 
  14.         elif number >=60 and number < 70
  15.                 print "Your Level is D" 
  16.         elif number < 60
  17.                 print "You not pass" 
  18.  
  19.  
  20. def main(): 
  21.     while True
  22.         number=raw_input("Please input your number:"
  23.         if number.isdigit(): 
  24.                 Input=int(number) 
  25.                 print "Your input is ",Input 
  26.                 compare(Input) 
  27.                 print "Press Ctrl + C to exit..." 
  28.         else
  29.                 print "Please input character ..." 
  30.                 print "Press Ctrl + C to exit..." 
  31.  
  32. main() 

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

 

 
 
  1. [root@centos6 20130113]# ./aa.py 
  2. This script make you input your number 
  3.  
  4. Then will show your level... 
  5. Please input your number:100 
  6. Your input is  100 
  7. Your Level is A 
  8. Press Ctrl + C to exit... 
  9. Please input your number:99 
  10. Your input is  99 
  11. Your Level is A 
  12. Press Ctrl + C to exit... 
  13. Please input your number:88 
  14. Your input is  88 
  15. Your Level is B 
  16. Press Ctrl + C to exit... 
  17. Please input your number:77 
  18. Your input is  77 
  19. Your Level is C 
  20. Press Ctrl + C to exit... 
  21. Please input your number:66 
  22. Your input is  66 
  23. Your Level is D 
  24. Press Ctrl + C to exit... 
  25. Please input your number:55 
  26. Your input is  55 
  27. You not pass 
  28. Press Ctrl + C to exit... 
  29. Please input your number:-100 
  30. Please input character ... 
  31. Press Ctrl + C to exit... 
  32. Please input your number:ijdf 
  33. Please input character ... 
  34. Press Ctrl + C to exit... 
  35. Please input your number: 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值