[ruby] drill output

Contents

image.png

Implementation

image.png

Commentary

① How to write by entering numerical values from the terminal ② How to write conditional branch

First of all, from ①. If you want to input from the terminal, use gets. If it is gets, the entered value will be a character string, so add .to_i after gets to make it gets.to_i. The to_i method is a method that converts to a number.

(2) (Conditional branch) uses an if statement. This time, we will use elsif and else to divide the conditions into three patterns. The condition this time is a comparison of numerical values. Use comparison operators such as <and == for comparison. This time, the comparison is 10 or less or 0 or less, so use <=. When = is added, it means the following or more. The difficult thing about this conditional expression is which condition to write from. image.png In this way, if you enter the conditional expression with a number of 10 or less first, even if input = -1, it will be applied to input <= 10, so if it is a number of 0 or less, it will not be output. Therefore, if it is not less than 10, it is greater than 10, so the condition for a value greater than 10 is written after else.

Recommended Posts

[ruby] drill output
[ruby] drill output
[ruby] drill output
[ruby] drill output
[ruby] drill output
[ruby] drill output
[ruby] drill output
Ruby input / output
Ruby standard output
Ruby logical operator drill
Ruby calorie calculation output
Output triangle in Ruby
[Ruby on Rails] CSV output function
String output method memo in Ruby
Ruby learning 4
[Ruby] Array
Ruby basics
Ruby learning 5
Ruby basics
Ruby Review 2
Ruby addition
Refactoring Ruby
Ruby learning 3
2020/10/4 Morning output
Ruby print puts p printf output method
2020/10/4 noon output
Learning output ~ 11/3 ~
Ruby setting 2
Ruby problem ⑦
2020/10/5 Morning output
Ruby learning 2
[Ruby] Block
Refactoring Ruby
ruby calculator
Ruby learning 6
Ruby settings 1
Refactoring Ruby
Learning output
2020/10/3 Noon output
Ruby basics
Ruby memo
Ruby learning 1
Ruby Review 1
From terminal to Ruby (standard input / output)
2020/10/3 Morning output
[Ruby] Module
Drill (self-made)
[Ruby] Difference between puts and return, output and return value