Menu
Coddy logo textTech

Recap - Range Practice

Part of the Logic & Flow section of Coddy's Ruby journey — lesson 9 of 56.

One challenge that pulls together inclusive ranges, range methods, and the case + range pattern.

challenge icon

Challenge

Easy

Read two integers (two lines of input): start and end_value. For every number in the inclusive range start..end_value, print one line in the format:

<n>: <label>

Where label is determined by a case on the number itself:

  • 1..3small
  • 4..6medium
  • 7..10large
  • anything else → out of scale

Then, on a final line, print the count of values that landed in 1..10 using include?.

For input 2 then 5, the output is:

2: small
3: small
4: medium
5: medium
In scale: 4

Try it yourself

start     = gets.to_i
end_value = gets.to_i

# TODO: iterate the range, print labels, and report how many were in 1..10

All lessons in Logic & Flow