Python Program
Python Program
Examples:
Input : x1, y1 = (3, 4)
x2, y2 = (7, 7)
Output : 5
The formula for distance between two point (x1, y1) and (x2, y2) is
Program
import math
# Function to calculate distance
def distance(x1 , y1 , x2 , y2):
return math.sqrt(math.pow(x2 - x1, 2) +math.pow(y2 - y1, 2))
# Drivers Code
print("%.6f"%distance(3, 4, 4, 3))
Output:
1.41421
(b) Write a program add.py that takes 2 numbers as
command line arguments and prints its sum.
import sys
def main():
# Check if exactly two command-line arguments (numbers) are provided
if len(sys.argv) != 3:
print("Usage: python add.py <number1> <number2>")
sys.exit(1) # Exit with an error code
try:
# Convert command-line arguments to numbers (integers in this case)
num1 = int(sys.argv[1])
num2 = int(sys.argv[2])
# Calculate the sum
except ValueError:
print("Error: Please provide valid integer numbers as arguments.")
# Constants
cover_price = 24.95
discount = 0.40
shipping_first = 3.00
shipping_additional = 0.75
copies = 60