Ruby and Shell scripts are used to pass the examination. rubyshell
Requirement: Enter the score on the keyboard to judge whether 0-59 is a failure. Print "You fail. Please try again next time !", 60-79: Pass, print "your score passed, please work harder !", 80-is a good score. Print "your score is excellent. Please make persistent efforts !", If you enter a score other than 0-, print "your score is excellent, please make persistent efforts !"
If the ruby method is used, the code is simplified as follows:
Copy codeThe Code is as follows:
#! /Usr/bin/ruby
Print "Enter your score :"
Grade = gets. to_ I
# Grade = name. to_ I
Case grade
When 0 .. 60
Puts "You fail. Please try again! "
When 61 .. 79
Puts "your score has passed. Please work harder! "
When 80 .. 100
Puts "your score is excellent. Please make persistent efforts! "
Else
Puts "the value you entered is incorrect. Please enter a value between 0 and !! "
End
If you use the if multiple selection methods in SHELL, the code is:
Copy codeThe Code is as follows:
#! /Bin/bash
Read-p "Please input your score:" Score
If [$ Score-ge 0-a $ Score-le 59]; then
Echo "You fail. Please try again! "
Elif [$ Score-ge 60-a $ Score-le 79]; then
Echo "your score passes. Please work harder! "
Elif [$ Score-ge 80-a $ Score-le 100]; then
Echo "your score is excellent. Please make persistent efforts! "
Else
Echo "the score you entered exceeds a reasonable value. Please enter it again! "
Fi
If the case method is used in SHELL, the Code is as follows:
Copy codeThe Code is as follows:
#! /Bin/bash
Read-p "Enter your exam score:" score
Case "$ score" in
[0-9])
Echo "You fail. Please try again! "
;;
[1-5] [0-9])
Echo "You fail. Please try again! "
;;
[6-7] [0-9])
Echo "your score passes. Please work harder! "
;;
[8-9] [0-9])
Echo "your score is excellent. Please make persistent efforts! "
;;
100)
Echo "your score is excellent. Please make persistent efforts! "
;;
*)
Echo "the score you entered exceeds a reasonable value. Please enter it again! "
;;
Esac