Last active
January 8, 2020 19:36
-
-
Save savaged/668b4254e8a859c9a548dd59fd3ce09c to your computer and use it in GitHub Desktop.
Python FizzBuzz (functional style)
This file contains 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 getVerb(i): | |
value = "" | |
r = i % 3 | |
if r == 0: | |
value = "Fizz" | |
r = i % 5 | |
if r == 0: | |
value = value + "Buzz" | |
if value == "": | |
value = i | |
return value | |
def getVerbs(integers = []): | |
verbs = [] | |
for i in integers: | |
verbs.append(getVerb(i)) | |
return verbs | |
def main(): | |
start = int(input("start: ")) | |
iterations = int(input("iterations: ")) | |
end = start + iterations | |
integers = range(start, end) | |
verbs = getVerbs(integers) | |
for verb in verbs: | |
print(verb) | |
print("Done!") | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment