Skip to content

Instantly share code, notes, and snippets.

@dmsurti
Created August 4, 2017 06:17
Show Gist options
  • Save dmsurti/ef139fe84408cc10a403563563ed9496 to your computer and use it in GitHub Desktop.
Save dmsurti/ef139fe84408cc10a403563563ed9496 to your computer and use it in GitHub Desktop.
#def is a keyword
# fizzbuzz_gen is the function name
# generates the fizzbuzz strings from 1 to n
def fizzbuzz_gen(n):
fizzbuzz_strings = []
for num in range(1, n + 1):
print("Fizz buzz counting up to {}".format(num))
if num % 3 == 0 and num % 5 == 0:
fizzbuzz_string.append("fizzbuzz")
elif num % 3 == 0:
fizzbuzz_string.append("fizz")
elif num % 5 == 0:
fizzbuzz_string.append("buzz")
else:
fizzbuzz_string.append(num)
return fizzbuzz_strings
fizzbuzz_100 = fizzbuzz_gen(100)
# fizzbuzz_100 will contain the 100 fizzbuzz strings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment