I’d like the program to exit if the input number is less than 0, but sys.exit() isn’t doing the trick. This is what I have now:
if len( sys.argv ) > 1:
number = sys.argv[1]
if number <= 0:
print "Invalid number! Must be greater than 0"
sys.exit()
Your test is failing because number is a string.
You need to convert
numberto an integer:Note that in Python 3.0 your code would have given an error, allowing you to find your mistake more easily: