Skip to content

Instantly share code, notes, and snippets.

@joshz
Created May 20, 2011 19:33
Show Gist options
  • Save joshz/983610 to your computer and use it in GitHub Desktop.
Save joshz/983610 to your computer and use it in GitHub Desktop.
FizzBuzz in Python
import cProfile
import pstats
def fizbuzz1():
for i in range(1, 101):
if (i % 3== 0) and (i % 5 == 0):
print('FizzBuzz')
elif i % 3 == 0:
print ('fizz')
elif i % 5 == 0:
print( 'buzz')
else:
print(i)
def fizbuzz2():
for i in range(1, 101):
print((i%3==0)*'Fizz'+(i%5==0)*'Buzz' or i)
if __name__ == '__main__':
cProfile.run('fizbuzz1()', 'f1')
cProfile.run('fizbuzz2()', 'f2')
p1 = pstats.Stats('f1')
p2 = pstats.Stats('f2')
p1.sort_stats('cumulative').print_stats(10)
p2.sort_stats('cumulative').print_stats(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment