Last active
March 1, 2017 05:43
-
-
Save Cr4ck3r/8f442521bfc93c20283ac7839c45aa11 to your computer and use it in GitHub Desktop.
Fizzbuzz with only one print python 3
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
| 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) |
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
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.