Saturday, April 14, 2018

My fizzbuzz

The "fizzbuzz test" is an interview question said to filter out the 99.0% of programming job candidates. The requirement are, write a short program that prints each number from 1 to 100 on a new line. For each multiple of 3, print “fizz”. For each multiple of 5, print “buzz”. For numbers which are multiples of both 3 and 5, print “fizzbuzz".

#!/usr/bin/env python3

for i in range(1, 101):
    print("%i:" % i, sep='',end='')
    if i % 3 == 0: print("fizz", end='')
    if i % 5 == 0: print("buzz", end='')
    print()

No comments:

Post a Comment