Python Program That Takes 2 Numbers and Prints Its Sum

Aim:

Write a python program add.py that takes 2 numbers as command-line arguments and prints its sum

Program:

step 1: open notepad and write the below program

import sys;
n1=int(sys.argv[1]);
n2=int(sys.argv[2]);
print (n1+n2)

step 2: SAVE
step 3: Open DOS SHELL and go to file saved location (D:\)
step 4: python filename.py argument1 argument2

Output:

python filename.py 10 20
30

Leave a Comment