Ex No 2
Ex No 2
Ex. No: 2a
Exchange the Values of Two Variables
Aim:
Algorithm
Step 1: Start.
Step 2: Read two variables a and b.
Step 3: Substitute the value of a by adding a and b.
Step 4: Substitute the value of b by subtracting a and b.
Step 5: Substitute the value of a by subtracting a and b.
Step 6: Print the exchanged value of a and b.
Step 7: Stop.
Program
Algorithm
Step 1: Start
Step 2: Read two variables a and b.
Step 3: Exchange the values of a and b by the expression a,b = b,a.
Step 4: Print the exchanged value of a and b.
Step 5: Stop.
Program
Conclusion
Thus, the exchange the values of two variables program is written and executed.
Ex. No: 2b
Circulate the Values of N Variables
Aim
Algorithm
Step 1: Start.
Step 2: Get the number of variables to be circulated as no_of_terms.
Step 3: Store the elements in a list.
Step 4: Each time, pop an element from the list, append it to the list, and print the list for every
pair of pop and append operations.
Step 5: Stop.
Program
Conclusion
Thus, the program for circulating the values of n variables is written and executed.
Ex. No: 2c
Distance Between Two Points
Aim
To write a Python program for finding the distance between two points.
Algorithm
Step 1: Start.
Step 2: Get the two points from the user (x1, y1) and (x2, y2).
Step 3: Calculate the distance between two points using the formula
Step 4: Display the calculated distance between two points.
Step 5: Stop
Program
x1=int(input("enter x1 : "))
x2=int(input("enter x2 : "))
y1=int(input("enter y1 : "))
y2=int(input("enter y2 : "))
result= ((((x2 - x1 )**2) + ((y2-y1)**2) )**0.5)
print("distance between",(x1,x2),"and",(y1,y2),"is : ",result)
Conclusion
Thus, the program for finding the distance between two points is written and executed.