今天看到了一个题目,需要输入一个数字,表示成绩和他的成绩的级别:
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: