Created
April 20, 2011 20:12
-
-
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
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 | |
# | |
# 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