Ruby program to take a number between 0 to 9 and print the word representation for that number
Following program shows you how to take a number between 0 to 9 and print the word representation for that number.
In this program we get numbers between 0 to 9 from user and print word representation using if condition
puts "Enter a number between 0 to 9:"
input = Integer(gets.chomp)
if input == 0
puts "Zero"
elsif input == 1
puts "One"
elsif input == 2
puts "Two"
elsif input == 3
puts "Three"
elsif input == 4
puts "Four"
elsif input == 5
puts "Five"
elsif input == 6
puts "Six"
elsif input == 7
puts "Seven"
elsif input == 8
puts "Eight"
elsif input == 9
puts "Nine"
else
puts "We don't have word representation for that number"
end
Output:
Example1:
Enter a number between 0 to 9:
3
Three
Example2:
Enter a number between 0 to 9:
8
Eight
Example3:
Enter a number between 0 to 9:
-2
We don't have word representation for that number