Forem

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)

Image of Bright Data

Maintain Seamless Data Collection – No more rotating IPs or server bans.

Avoid detection with our dynamic IP solutions. Perfect for continuous data scraping without interruptions.

Avoid Detection

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay