DEV Community

es404020
es404020

Posted on

Working with numbers Ruby

We shall be using Replt as our play ground environment for ruby.

Numbers in ruby can be integer or float depending on how it was specified

puts "Enter first number"
var1.to_i = get.chomps

puts "Enter second number"
var2.to_i = get.chomps

puts "your result is #{var1.to_i + var2.to_i}"

Enter fullscreen mode Exit fullscreen mode

to_i:convert to string
to_f:convert to float
rand:generate random value
.time:repeat a variable by x times

20.times {rand(100)}


Enter fullscreen mode Exit fullscreen mode

You can guess the answer i owe you a bottle of beer.You can experiment with more arithmetic operators like + ,/,-,%

Top comments (0)