Created
October 29, 2009 07:25
-
-
Save tstone/221242 to your computer and use it in GitHub Desktop.
Recursive Python FizzBuzz solution
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
def fizzbuzz (start, end): | |
if start % 15 == 0: | |
print 'fizzbuzz' | |
elif start % 3 == 0: | |
print 'fizz' | |
elif start % 5 == 0: | |
print 'buzz' | |
else: | |
print start | |
if start < end: | |
fizzbuzz(start+1, end) | |
fizzbuzz(1, 100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your implementation can be rewritten with the signature
def fizbuzz(end, start=1)
and called accordingly. Externally this updated call can then still be called the normal way, i.e. asfizzbuzz(100)
.Anyhow, here is my recursive Python 3 implementation which doesn't require
start
: