Skip to content

Instantly share code, notes, and snippets.

@SeanPlusPlus
Created April 20, 2011 20:12
Show Gist options
  • Save SeanPlusPlus/932600 to your computer and use it in GitHub Desktop.
Save SeanPlusPlus/932600 to your computer and use it in GitHub Desktop.
SequentialNumGen.py accepts exactly two integers as arguments, and prints the range between them to terminal
#!/usr/bin/env python
#
# SequentialNumGen.py
#
# accepts exactly two integers as arguments,
# and prints the range between them to terminal
from sys import exit
import optparse
def usage():
print "usage: SequentialNumGen.py num1 num2 (num1 must be less than num2)"
def getArgs():
parser = optparse.OptionParser()
opts, args = parser.parse_args()
if not args:
parser.print_help()
sys.exit(1)
return opts, args
def main():
opts, args = getArgs()
try:
int(args[0])
int(args[1])
except ValueError:
exit(usage())
START = int(args[0])
END = int(args[1]) + 1
if ( START > END ):
exit(usage())
print ("\n".join(map(str, range(START,END))))
if __name__ == '__main__':
main()
# SAMPLE OUTPUT:
#
# $ SequentialNumGen.py 1 10
# 1
# 2
# 3
# 4
# 5
# 6
# 7
# 8
# 9
# 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment