Ruby and Shell scripts are used to pass the examination. rubyshell

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.