Return to Blog entry
# And even shorter than the initial fixed version! def flex_fizzbuzz( start = 1, end = 101, mark = { 3:'Fizz', 5:'Buzz' } ): for n in range( start, end ): result = "" for val in mark: if not n % val: result += mark[ val ] print result or n
# Sample of a more flexible call - don't count this for my code lines count - just a demo! if __name__ == "__main__": print "Old School" flex_fizzbuzz() print "Flex Version 3=Fizz, 5=Buzz, 7=Bang, 13=Boom for 1-150" flex_fizzbuzz( 1, 150, {3:'Fizz', 5:'Buzz', 7:'Bang', 13:'Boom'} )