Inlab2 SkillRack(Diagonal Length)

Q.Given two adjacent vertices of a square, write an algorithm and the subsequent python code to determine the length of the diagonal. Pythagorean theorem states that the square of the hypotenuse  is equal to the sum of the square of the other two sides.

Input Format:

X - co-ordinate of the first vertex of the square

Y - co-ordinate of the first vertex of the square

X - co-ordinate of the second vertex of the square

Y - co-ordinate of the second vertex of the square

Output Format:

The other two vertices of the square as a tuple,one in each line

Diagonal of the square with two decimal places only.

Algorithm:

Step1. Get the input of x,y coordinates of the of the adjacent two vertices and store it in x1,y1,x2,y2 variables

Step2. Check if x1 == x2 if true proceed to step2.1 else proceed to step3

Step2.1 length of side(distance) is equal to y2 - y1

Step2.2 length of diagonal(diag) is square root of 2 multiplied by distance

Step2.3 let x3 is equal to the sum of x2 and distance

Step2.4 let x4 is equal to x3

Step2.5 let y3 be equal to y2 and y4 be equal to y1

Step3.check if y1==y2 if true proceed to step3.1

Step3.1 distance is equal to the difference of x2 and x1

Step3.2 length of diagonal(diag) is square root of 2 multiplied by distance

Step3.3 let y3 is equal to the sum of y2 and distance

Step3.4 let y4 is equal to y3

Step3.5 let x3 be equal to x2 and x4 be equal to x1

Step4. Display (x3,y3) and (x4,y4)

Step5. Display the length of the diagonal (stored in variable diag)

Step6. End



Program:

https://gist.github.com/kausthub13/e6c72601b0c2693fb95b1fb088e0e9c8



Output:

Screenshot (1).png

No comments:

Post a Comment

Bonus Practice Problems(GMT To IST)

IST (Indian Standard Time) is 5 hours 30 minutes ahead of GMT(Greenwich Mean Time). Develop an algorithm and write the Python code to find...