Skip to content

Instantly share code, notes, and snippets.

@svalleru
Last active October 16, 2015 19:39
Show Gist options
  • Save svalleru/536273edb9f42366109a to your computer and use it in GitHub Desktop.
Save svalleru/536273edb9f42366109a to your computer and use it in GitHub Desktop.
#Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the
#multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz"
for i in xrange(1, 101):
if i % 15 == 0: #L.C.M of 3 & 5
print "FizzBuzz"
elif i % 3 == 0:
print "Fizz"
elif i % 5 == 0:
print "Buzz"
else:
print i
#Pythonic Way
["Fizz"*(i%3==0) + "Buzz"*(i%5==0) or i for i in range(1,101)]
#Pythonic Way + String
','.join(str(e) for e in ["Fizz"*(i%3==0) + "Buzz"*(i%5==0) or i for i in range(1,101)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment