Menu

Sign in to track your progress and unlock all features.

Theme style

Start learning freeLog in

Problem No 18

Return FizzBuzz Value

Medium

≈ 18 minute session

Summary

Return the classic FizzBuzz response for a given integer using if/elif/else logic.

Problem statement

Write a function fizzbuzz(n) that returns: - 'FizzBuzz' if n is divisible by both 3 and 5. - 'Fizz' if n is divisible by 3 only. - 'Buzz' if n is divisible by 5 only. - Otherwise, return the string representation of n. Make sure the check for divisibility by both 3 and 5 happens before the individual checks.

Task

Practice ordering of conditional checks (especially for multiples of both 3 and 5) and returning strings.

Examples

Divisible by 3

Input

fizzbuzz(9)

Output

Fizz

Explanation

9 is divisible by 3 so return 'Fizz'.

Input format

An integer n passed to fizzbuzz(n).

Output format

A string: 'Fizz', 'Buzz', 'FizzBuzz', or the string form of n.

Constraints

n is an integer (can be zero or negative).

Samples

Sample input 0

fizzbuzz(5)

Sample output 0

Buzz

Explanation 0

5 is divisible by 5.

Code editor
Loading editor…

AI assistant

Ask me anything!

Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.

Chat history is temporary and will not be saved.

Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.