The integer N is given as input.
Display integers from 1 to N in order from 1.
However, the number you are trying to display is
・ When it is a multiple of 3 and a multiple of 5, "Fizz Buzz" ・ When it is a multiple of 3, "Fizz" ・ When it is a multiple of 5, "Buzz"
Please display instead of the numerical value.
The input is given in the following format.
N
N is an integer greater than or equal to 1 and less than or equal to N.
At the end, start a new line and do not include extra characters or blank lines.
20
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 Fizz Buzz 16 17 Fizz 19 Buzz
python
num = gets.to_i
(1..num).each do |n|
if n % 15 == 0
puts "Fizz Buzz"
elsif n % 5 == 0
puts "Buzz"
elsif n % 3 == 0
puts "Fizz"
else
puts n
end
end
Recommended Posts