livepython.net

190. Python Program to Play FizzBuzz from 1 to N

EasyPhase 1 · Warm-up

You know for loops, if and the % sign. That is all you need here.

Overview

FizzBuzz is a counting game. It is one of the most common first questions in coding interviews.

Problem Statement

Amara teaches a counting game to a class. The class counts from 1 up to a number n. Some numbers get a word instead:

  • A number that can be divided by 3 is Fizz.
  • A number that can be divided by 5 is Buzz.
  • A number that can be divided by both 3 and 5 is FizzBuzz.
  • Every other number stays a number.

Read n and print one line for each number from 1 to n.

Steps

  1. Read n and turn it into a whole number.
  2. Loop over every number from 1 to n.
  3. Check "3 and 5" first, then 3, then 5.
  4. Print the word, or the number when no word fits.

Examples

Example 1. Input 5 gives:

1
2
Fizz
4
Buzz

Why: 3 can be divided by 3, so it is Fizz. 5 can be divided by 5, so it is Buzz.

Example 2. Input 15 ends with these lines:

13
14
FizzBuzz

Why: 15 can be divided by 3 and by 5, so it is FizzBuzz, not Fizz.

Input

One whole number n (1 or more). Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Output

One line for each number from 1 to n. The tests try 4 different inputs.

Try it first. The solution opens when you solve this question, or after 3 tries with Submit.

Finish this chapter firstChapter 10 · For Loops
solution.py
# write your code here

EXPECTED OUTPUT

11
22
3Fizz
44
5Buzz

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.