Skip to the content

Project: FizzBuzz

Python · Unit 3: Loops

FizzBuzz is an interview classic: you count from 1, but the multiples of 3 say Fizz, the ones of 5 say Buzz and the ones of both say FizzBuzz.

Watch out: 15 is a multiple of 3 and of 5, so the order of the conditions matters.

n = 15
print(n % 3 == 0)
print(n % 5 == 0)

Prints

True
True

Exercises in this lesson

You do them in the app, which checks them on the spot and explains why.

  1. 1. Write the code

    Write fizzbuzz(n). Return "FizzBuzz" if n is a multiple of 3 and of 5, "Fizz" if it is a multiple of only 3, "Buzz" if only of 5 and, if not, the number as text.

  2. 2. Write the code

    You already have your function. Now the person types how far to play. Use a loop to print fizzbuzz of each number, from 1 up to that number included.

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →