Last active
September 25, 2018 05:49
-
-
Save yattom/626bf4059aff2aaf7aae55f66a7d3f6e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[print(("Fizz" if i%3==0 else "") + ("Buzz" if i%5 == 0 else "") or str(i)) for i in range(1,101)] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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