Skip to content

Instantly share code, notes, and snippets.

@unrivaledcreations
Created November 3, 2017 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unrivaledcreations/4cd736f65ccc9928ca02fc57665fc2ea to your computer and use it in GitHub Desktop.
Save unrivaledcreations/4cd736f65ccc9928ca02fc57665fc2ea to your computer and use it in GitHub Desktop.
FizzBuzz Solution in Python
def fizzbuzz(n):
answer = ''
fizz = not n % 3
buzz = not n % 5
if (fizz):
answer += 'Fizz'
if (buzz):
answer += 'Buzz'
if (not fizz and not buzz):
answer += str(n)
return answer
for n in range(1,100+1): # +1 makes the 1-100 thing more readable.
print(fizzbuzz(n))
@unrivaledcreations
Copy link
Author

unrivaledcreations commented Nov 4, 2017

This is an example of human-readable Python code. This entire exercise could be written in a single line of code: See this very, very excellent example FizzBuzz solution by @Kapppa. Kapppa's example shows a very deep understanding of the Python language which went straight into my cookbook. The contrast between the one-line solution and the solution given here (in this gist), raises questions about the moral dilemma: Should one write over-optimize software code; or should one write longer code for easier future code maintenance and human-readable clarity?

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