DEV Community

AbreuY
AbreuY

Posted on

2 1

[Python] Looping with FizzBuzz

Statement:
Write the code needed to print to the console all the numbers from 1 to 100.

  • For multiples of 3, instead of the number, print Fizz.
  • For multiples of 5, print Buzz.
  • For numbers which are multiples of both 3 and 5, print FizzBuzz.

Solution:

for i in range(1, 101):

    if i % 3 == 0:
        print("Fizz")
    elif i % 5 == 0:
        print("Buzz")
    else:
        print(i)

    if i % 3 == 0 and i % 5 == 0:
        print("FizzBuzz")
Enter fullscreen mode Exit fullscreen mode

View the working code

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay