beginner in python, please take a look at the below code:
import sys
if __name__ == '__main__':
n = int(sys.argv[1])
i=1
s=0
while i<n:
if (i % 3 == 0 and i % 5 == 0):
pass
elif (i % 3 == 0):
s = s+i
elif (i % 5 == 0):
s = s+i
i=i+1
print 'The sum is of all 3s and 5s till {}: {}'.format(n,s)
The error keeps coming out, I don't know how to solve it:
2 import sys
3 if __name__ == '__main__':
----> 4 n = int(sys.argv[1])
5 i=1
6 s=0
IndexError: list index out of range
Thank you!
python script.py argument.import sys if __name__ == '__main__': print sys.argvand runpython script.py 1. after this runpython script.py 1 2 3and you will understand how it works