id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

chanr@sfusd.edu pythonfunctionsfour > fizzbuzz
prev  |  next  |  chance

Write a function that returns a list of the numbers from 1 up to but not including n. But for numbers that are multiples of three replace the number with "Fizz" and for the multiples of five replace with "Buzz". For numbers which are multiples of both three and five, replace with "FizzBuzz". (FizzBuzz is a child's game, a drinking game, and a well-known test for programming competence.)


fizzbuzz(10) → [1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz']
fizzbuzz(20) → [1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz', 'Buzz', 11, 'Fizz', 13, 14, 'FizzBuzz', 16, 17, 'Fizz', 19]
fizzbuzz(1) → []

...Save, Compile, Run (ctrl-enter)

def fizzbuzz(n):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Difficulty: 70 Post-solution available

Copyright Nick Parlante 2017 - privacy