Skip to content

Instantly share code, notes, and snippets.

@savaged
Last active January 8, 2020 19:36
Show Gist options
  • Save savaged/668b4254e8a859c9a548dd59fd3ce09c to your computer and use it in GitHub Desktop.
Save savaged/668b4254e8a859c9a548dd59fd3ce09c to your computer and use it in GitHub Desktop.
Python FizzBuzz (functional style)
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