Requirements: input fractions from the keyboard, judging by this, 0-59 for failing, print "You did not pass, please work hard next time!", 60-79 for passing, print "Your grades pass, please try harder!" ", 80-100 for good results, print" Your score for excellence, please continue! ", if you enter a score other than 0-100, print" Your grades are excellent, please try again! "
If you use Ruby, the code is more streamlined, as follows:
#!/usr/bin/rubyprint "Please enter your score:" grade = Gets.to_i#grade = Name.to_icase grade when 0..60 puts "you did not pass, please work hard next time!" when 61..79 Puts "Your grades have passed, please try harder!" When 80..100 puts "Your grades are excellent, please keep up!" Else puts "you entered the wrong number, please enter a value between 0-100!" End
If you use the If multi-select method in the shell, the code is:
#!/bin/bashread-p "Please input your score:" Scoreif [$Score-ge 0-a $Score-le-];then echo "You failed to pass the next effort!" elif [$Score-ge 60-a $Score-le];then echo "Your grades pass, please try harder!" elif [$Score-ge 80-a $Score-le];then echo "Your score is excellent, please try again!" else echo "You have entered more than a reasonable value, please re-enter!" Fi
In the shell, if the case method is more troublesome, the code is:
#!/bin/bashread-p "Please enter your test score:" Scorecase "$score" in[0-9]) echo "You did not pass, please work hard next time!"; [1-5] [0-9] echo "You did not pass, please work hard next time!"; [6-7] [0-9] echo "Your grades pass, please try harder!"; [8-9] [0-9] echo "Your score is excellent, please try again!"; echo "Your grades are excellent, please try again!";; *) echo "The result you entered is above reasonable value, please re-enter!"; Esac
This article is from the "Fuqin Wine" blog, please make sure to keep this source http://yuhongchun.blog.51cto.com/1604432/1588063
Write a script that judges the classification of grades in Ruby