Skip to content

Instantly share code, notes, and snippets.

@tmodrzynski
Last active January 2, 2017 13:50
Show Gist options
  • Save tmodrzynski/d099014e05d3b4bb25a4 to your computer and use it in GitHub Desktop.
Save tmodrzynski/d099014e05d3b4bb25a4 to your computer and use it in GitHub Desktop.
Python developer - coverage question easy
def fizzbuzz(count):
"""FizzBuzz implementation
Returns list of output messages.
"""
if not isinstance(count, int):
raise TypeError('count must be an integer')
if count < 1 or count > 1000:
raise ValueError('count must be between 1 and 1000')
results = []
for num in xrange(1, count+1):
if num % 3 == 0 and num % 5 == 0:
results.append('FizzBuzz')
elif num % 3 == 0:
results.append('Fizz')
elif num % 5 == 0:
results.append('Buzz')
else:
results.append(str(num))
return results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment