Created
December 15, 2011 03:53
-
-
Save yanolab/1479761 to your computer and use it in GitHub Desktop.
fizzbuzz
This file contains 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
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys | |
def main(maxnum): | |
for idx in xrange(1, maxnum+1): | |
val = idx | |
if idx % 3 == 0: | |
val = "Fizz" | |
if idx % 5 == 0: | |
val = "Buzz" | |
if idx % 15 == 0: | |
val = "FizzBuzz" | |
print val | |
def usage(): | |
"""print usage""" | |
print "usage: python fizzbuzz.py maxnumber" | |
def error(msg): | |
"""print error message, usage and exit program""" | |
print "error: %s" % msg | |
usage() | |
sys.exit(1) | |
if __name__ == "__main__": | |
if len(sys.argv) != 2: | |
error("invalid argments") | |
num = sys.argv[1] | |
if not num.isdigit(): | |
error("maxnumber must be digit") | |
main(int(num)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment