Write a script that judges the classification of grades in Ruby

Source: Internet
Author: User

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

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.