Fizz Buzz in Python

2009

Jeff Atwood of Coding Horror has developed a sure fire test to filter out good programmers from bad ones. It's called the FizzBuzz test, and it's a very simple problem to solve.FizzBuzz became legendary in programming interviews because it revealed a shocking truth: many candidates who claimed programming experience couldn't write even the simplest code. The test exposes basic gaps in understanding loops, conditionals, and modular arithmetic. Enjoy!If you'd like to learn more about programming, contact me for a one-on-one lesson.

for i in range(1, 101):
    if not i % 15:
        print "FizzBuzz"
    elif not i % 3:
        print "Fizz"
    elif not i % 5:
        print "Buzz"
    else:
        print i

This solution demonstrates Python's elegance through its concise syntax. Note the clever use of i % 15 first—since 15 is the least common multiple of 3 and 5, this catches multiples of both without nested conditions.