Skip to content

Instantly share code, notes, and snippets.

@yanolab
Created December 15, 2011 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanolab/1479761 to your computer and use it in GitHub Desktop.
Save yanolab/1479761 to your computer and use it in GitHub Desktop.
fizzbuzz
#! /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