Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@unrivaledcreations 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