How extract count of even number and display them


#1

Hello,
I’m totally new to Ruby and I am trying to code the following:
Print and count even numbers existing before value “N”.
Ex: If number 9 is entered, code will print : 0,2,4,6,8 and total count:
5
Any help would be appreciated!


#2

What exactly is your question?


#3

Luc Lucas wrote in post #1185718:

Hello,
I’m totally new to Ruby and I am trying to code the following:
Print and count even numbers existing before value “N”.
Ex: If number 9 is entered, code will print : 0,2,4,6,8 and total count:
5
Any help would be appreciated!

N=11
puts “nb=#{(N+1)/2}”
(0…N).step(2) {|x| p x}

https://github.com/glurp/ruby-mini-book