Exercise - 2 Distance Between Two Points and Command Line Arguments

EXERCISE - 2

2 A) AIM: Write a program to compute distance between two points taking input from the user (Pythagorean Theorem)

B) AIM: Write a program add.py that takes 2 numbers as command line arguments and prints its sum.

2 A) AIM: Write a program to compute distance between two points taking input from the user (Pythagorean Theorem)

SOURCE CODE:

import math
x1=int(input("Enter number:"))
x2=int(input("Enter number:"))
y1=int(input("Enter number:"))
y2=int(input("Enter number:"))
distance=math.sqrt((x2-x1)**2+(y2-y1)**2)
print("Distance between two points is : ",distance)

OUTPUT:

Enter number:5
Enter number:8
Enter number:4
Enter number:9
Distance between two points is :  5.830951894845301

2 B) AIM: Write a program add.py that takes 2 numbers as command line arguments and prints its sum.


SOURCE CODE:

import sys
sum=int(sys.argv[1])+int(sys.argv[2])
print("Sum of two numbers is:",sum)


OUTPUT:

>python add.py 9 7
Sum of two numbers is:16