Skip to content

Instantly share code, notes, and snippets.

@Cr4ck3r
Last active March 1, 2017 05:43
Show Gist options
  • Save Cr4ck3r/8f442521bfc93c20283ac7839c45aa11 to your computer and use it in GitHub Desktop.
Save Cr4ck3r/8f442521bfc93c20283ac7839c45aa11 to your computer and use it in GitHub Desktop.
Fizzbuzz with only one print python 3
fblist = []
for n in range (1,101):
if n % 3 == 0 and n % 5 == 0:
fblist.append("fizzbuzz")
elif n % 3 == 0:
fblist.append("fizz")
elif n % 5 == 0:
fblist.append("buzz")
else:
fblist.append(n)
print (*fblist)
@dmsurti
Copy link

dmsurti commented Feb 27, 2017

For counting fizzbuzz upto small numbers, this is OK, otherwise for large number say a million, your runtime memory will be an array of 1,000,000 fizz and buzz strings! You want to avoid that.

@dmsurti
Copy link

dmsurti commented Feb 27, 2017

Take this as an extra challenge. How you can avoid the runtime large memory usage with the above code? HINT: Think file on disk!

Also you can do this challenge sometime later when you get a chance, as a review exercise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment