Python: Test AB and CD are orthogonal or not
Python Basic - 1: Exercise-55 with Solution
There are four different points on a plane, P(xp,yp), Q(xq, yq), R(xr, yr) and S(xs, ys). Write a Python program to determine whether AB and CD are orthogonal.
xp,yp, xq, yq, xr, yr, xs and ys are -100 to 100 respectively and each value can be up to 5 digits after the decimal point It is given as a real number including the number of. Output:
Output AB and CD are not orthogonal! or AB and CD are orthogonal!.
while True: try: print("Input xp, yp, xq, yq, xr, yr, xs, ys:") x_p, y_p, x_q, y_q, x_r, y_r, x_s, y_s = map(float, input().split()) pq_x, pq_y = x_q - x_p, y_q - y_p rs_x, rs_y = x_s - x_r, y_s - y_r rs = pq_x*rs_x + pq_y*rs_y if abs(rs) > 1e-10: print("AB and CD are not orthogonal!") else: print("AB and CD are orthogonal!") except: break
Input xp, yp, xq, yq, xr, yr, xs, ys: 4.5 -2.5 -2.5 4.5 3.5 3.5 3.8 -3.5 AB and CD are not orthogonal!
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to create maximum number of regions obtained by drawing n given straight lines.
Next: Write a Python program to sum of all numerical values (positive integers) embedded in a sentence.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join