Python interpreter gives Syntax error while running below code:
import sys if len(sys.argv) == 3: a=sys.argv[1] b=sys.argv[2] sum=int(a) + int(b) print "The sum is: ", sum elif len(sys.argv) != 3: print "Only two arguments allowed !" else: print "Please enter two numbers as argument with the script. Try again !" Error:
luckee@zarvis:~/python$ ./sumtwo.py 5 10 ./sumtwo.py: line 3: syntax error near unexpected token `sys.argv' ./sumtwo.py: line 3: `if len(sys.argv) == 3:'
python sumtwo.pyor adding#!pythonas a first file of your file.ifandelifclauses cover every possibilty - len(sys.argv) has to be either == 3 or != 3. The else will never get triggered.