Skip to content

Instantly share code, notes, and snippets.

@yattom
Last active September 25, 2018 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yattom/626bf4059aff2aaf7aae55f66a7d3f6e to your computer and use it in GitHub Desktop.
Save yattom/626bf4059aff2aaf7aae55f66a7d3f6e to your computer and use it in GitHub Desktop.
[print(("Fizz" if i%3==0 else "") + ("Buzz" if i%5 == 0 else "") or str(i)) for i in range(1,101)]
def fizzbuzz(i):
if i % 15 == 0:
return "FizzBuzz"
elif i % 3 == 0:
return "Fizz"
elif i % 5 == 0:
return "Buzz"
else:
return str(i)
for i in range(1, 101):
print(fizzbuzz(i))
class FizzBuzz:
def __init__(self):
self.i = 1
def __iter__(self):
while self.i <= 100:
s = self.helper(3, "Fizz")
s += self.helper(5, "Buzz")
if not s:
s = str(self.i)
yield s
self.i += 1
def helper(self, m, s):
return s if self.i % m == 0 else ""
for s in FizzBuzz():
print(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment