Skip to content

Instantly share code, notes, and snippets.

@jasonsperske
Created July 20, 2012 18:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonsperske/3152293 to your computer and use it in GitHub Desktop.
Save jasonsperske/3152293 to your computer and use it in GitHub Desktop.
A cleaner Fizz/Buzz in Python
# My Third Python program
# Based on this spec: http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html
import time
import random
def fbPrinter(simulator, translator, i):
time.sleep(simulator(i))
print(translator(i))
def fbTranslator(n):
output = '{0}'.format(n)
if n % 15 == 0:
return '{0}, uh I mean "FizzBuzz"! Said the child'.format(n)
elif n % 5 == 0:
return 'Buzz!'
elif n % 3 == 0:
return 'Fizz!'
return output
def fbSimulateProficiency(n):
if n % 15 == 0:
return random.randint(3, 5)
elif n % 5 == 0:
if i < 20:
return random.randint(2, 3)
elif i < 20:
return random.randint(1,3)
return random.randint(0, 1)
[fbPrinter(fbSimulateEfficiency, fbTranslator, i) for i in range(1, 100)]
@jasonsperske
Copy link
Author

Switched over to passing functions (cleaner)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment