Read the question, write Python on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
The famous interview warm-up. Read n and print the numbers 1 to n, one per line.
Replace multiples of 3 with Fizz, multiples of 5 with Buzz, and multiples of both with FizzBuzz.
Input. One line: an integer n ≥ 1.
Output. n lines of numbers or Fizz/Buzz/FizzBuzz.
Constraints
- 1 ≤ n ≤ 100
Examples
Input
5
Output
1 2 Fizz 4 Buzz
Hint
- Check divisibility by 15 first — a number divisible by both 3 and 5 must be handled before the single checks.
- Equivalently: build the word from "Fizz" if i%3==0 plus "Buzz" if i%5==0, and fall back to the number.
Show correct code
Peek only after you have tried. You can still Check your own version.
n = int(input())
for i in range(1, n + 1):
if i % 15 == 0:
print("FizzBuzz")
elif i % 3 == 0:
print("Fizz")
elif i % 5 == 0:
print("Buzz")
else:
print(i)
main.pyPython · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.