The ruby version of the guessing numbers game

Source: Internet
Author: User

Puts "Please input Number1:" #提示输入第一个数number1 =gets# Save the first number puts "please input a operator (+,-, *,/):" Op=getsputs "in Put Number2: "Number2=getscase op.chomp# performs the corresponding operation according to the operator when" + "Result=number1.to_i+number2.to_iwhen"-"result= Number1.to_i-number2.to_iwhen "*" Result=number1.to_i*number2.to_iwhen "/" result=number1.to_i/number2.to_iend# Output calculation result puts "Result:#{number1.chomp}#{op.chomp}#{number2.chomp}=#{result}"

Operation Result:

G:\share\ruby>ruby Number_guess.ry

Please enter a number between 0-100 to guess the size of the number randomly generated by the program

50

The number you entered is too small.

Please enter a number between 0-100 to guess the size of the number randomly generated by the program

75

The number you entered is too small.

Please enter a number between 0-100 to guess the size of the number randomly generated by the program

82

The number you entered is too small.

Please enter a number between 0-100 to guess the size of the number randomly generated by the program

91

The number you entered is too small.

Please enter a number between 0-100 to guess the size of the number randomly generated by the program

96

The number you entered is too small.

Please enter a number between 0-100 to guess the size of the number randomly generated by the program

98

The number you typed is too big.

Please enter a number between 0-100 to guess the size of the number randomly generated by the program

97

Congratulations, you guessed right.

Count=7


G:\share\ruby>


The ruby version of the guessing numbers game

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.