Requirements for: input points from the keyboard, in order to judge, 0-59 for the failure, print "You did not pass, please try next time!", 60-79 for passing, print "Your grades pass, please work harder!" ", 80-100 for good results, print" Your results for the excellent, please make persistent efforts! "If you enter a score other than 0-100, please print" Your results for excellence, please make efforts! "
If you use Ruby, the code is simpler, as follows:
Copy Code code as follows:
#!/usr/bin/ruby
Print "Please enter your score:"
Grade = Gets.to_i
#grade = Name.to_i
Case Grade
When 0..60
Puts "You did not pass, please try next time!"
When 61..79
Puts "Your grades have passed, please work harder!"
When 80..100
Puts "Your achievements for the outstanding, please make efforts!"
Else
Puts "The number you entered is incorrect, please enter a value between 0-100!!"
End
In the shell, if you select a method with multiple branches, the code is:
Copy Code code as follows:
#!/bin/bash
Read-p "Please input your score:" Score
If [$Score-ge 0-a $Score-le];then
echo "You didn't pass, please try again next time!"
elif [$Score-ge 60-a $Score-le];then
echo "Your grades pass, please work harder!"
elif [$Score-ge 80-a $Score-le];then
echo "Your results are excellent, please make efforts!"
Else
echo "You have entered a score that exceeds the reasonable value, please re-enter!"
Fi
In the shell, if the method of using the case is more troublesome, the code is:
Copy Code code as follows:
#!/bin/bash
Read-p "Please enter your test score:" Score
Case "$score" in
[0-9])
echo "You didn't pass, please try again next time!"
;;
[1-5] [0-9])
echo "You didn't pass, please try again next time!"
;;
[6-7] [0-9])
echo "Your grades pass, please work harder!"
;;
[8-9] [0-9])
echo "Your results are excellent, please make efforts!"
;;
100)
echo "Your results are excellent, please make efforts!"
;;
*)
echo "You have entered a score that exceeds the reasonable value, please re-enter!"
;;
Esac