Skip to content

Instantly share code, notes, and snippets.

@lynnlangit
Created August 10, 2015 20:40
Show Gist options
  • Save lynnlangit/62140fb94b0752334fea to your computer and use it in GitHub Desktop.
Save lynnlangit/62140fb94b0752334fea to your computer and use it in GitHub Desktop.
FizzBuzz Python Example
def fizzbuzz(intList):
if intList % 3 == 0 and intList % 5 == 0:
print "Fizzbuzz"
elif intList % 3 == 0:
print "Fizz"
elif intList % 5 == 0:
print "Buzz"
else:
print intList
print "\n".join(fizzbuzz(intList) for intList in (range(1, 101)))
@AlmightyOatmeal
Copy link

You're printing to STDOUT, not returning a value, so this code will fail like this:

Traceback (most recent call last):
  File "fb.py", line 11, in <module>
    print "\n".join(fizzbuzz(intList) for intList in (range(1, 101)))
TypeError: sequence item 0: expected string, NoneType found

The use of the variable name 'intList' is a bit misleading as you're passing in a single value, not a list.

You're performing the same two arithmetic operations twice (each) so that's doing more work than is necessary.

If you would like some pointers then I would be more than willing to help :)

-Jamie Ivanov
(If you google me then you should find me otherwise my google email is my first name, period, my last name.)

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