Hackbright Code Challenges

FizzBuzz

FizzBuzz

Whiteboard

Easier

Concepts

Loops

Download

fizzbuzz.zip

Solution

FizzBuzz: Solution


Write a program that counts from 1 to 20 in fizzbuzz fashion.

To do so, loop from 1 to 20 (inclusive). Each time through, if the number is evenly divisible by 3, say ‘fizz’. If the number is evenly divisible by 5, say ‘buzz’. If the number is evenly divisible by both 3 and 5, say ‘fizzbuzz’. Otherwise, say the number.

For example:

>>> fizzbuzz()
1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz
16
17
fizz
19
buzz

We given you a file, fizzbuzz.py, with a method, fizzbuzz:

def fizzbuzz():
    """Count from 1 to 20 in fizzbuzz fashion."""

However, this method is unimplemented.