![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check whether the point (x, y) lies on a given line in Python
Suppose we have a straight line in the form y = mx + b, where m is slope and b is y-intercept. And have another coordinate point (x, y). We have to check whether this coordinate point lies on that straight line or not.
So, if the input is like m = 3 b = 5 point = (6,23), then the output will be True as if we put the given x and y coordinate values on the straight line equation then it will satisfy.
To solve this, we will follow these steps −
- if y of point is same as (m * x of point) + b, then
- return True
- return False
Let us see the following implementation to get better understanding −
Example Code
def solve(m, b, point): if point[1] == (m * point[0]) + b: return True return False m = 3 b = 5 point = (6,23) print(solve(m, b, point))
Input
3, 5, (6,23)
Output
True
Advertisements