Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This program will contain two functions, slope and intercept
- 2 # slope_intercept.py
- 3
- 4 import math
- 5
- 6 def slope(x1,y1,x2,y2):
- 7 """This function finds the slope of a line (int or float format)"""
- 8 rise = (y2 - y1)
- 9 run = (x2 - x1)
- 10 slope = (rise / run)
- 11 if type(slope) == float: #checks to see if numbers are int or float
- 12 return round(slope,2)
- 13 else:
- 14 return slope
- 15
- 16 def intercept(x1,y1,slope):
- 17 """This function figures the y-intercept of a line"""
- 18 a = slope * x1
- 19 intercept = y1 - a
- 20 return intercept
- 21
- 22 def main():
- 23
- 24 print("Enter the first set of point coordinates separated by a comma. ")
- 25 x1,y1 = input()
- 26 print("Enter the second set of point coordinates separated by a comma. ")
- 27 x2,y2 = input()
- 28 print("The slope of those coordinates is: ") , slope(x1,y1,x2,y2)
- 29 print("The y-intercept of that line is: ") , intercept(x1,y1,slope)
- ,30
- 31
- 32 if __name__ == "__main__":
- 33 main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement