Python: Calculate midpoints of a line
Python Basic: Exercise-73 with Solution
Write a Python program to calculate midpoints of a line.
Sample Solution:-
print('\nCalculate the midpoint of a line :')
x1 = float(input('The value of x1 (the first endpoint) '))
y1 = float(input('The value of y1 (the first endpoint) '))
x2 = float(input('The value of x2 (the second endpoint) '))
y2 = float(input('The value of y2 (the second endpoint) '))
x_m_point = (x1 + x2)/2
y_m_point = (y1 + y2)/2
print();
print("The midpoint of line is :")
print( "The midpoint's x value is: ",x_m_point)
print( "The midpoint's y value is: ",y_m_point)
print();
========== RESTART: F:/Python_APSC/py-ex-basic-73.py =========
Calculate the midpoint of a line :
The value of x1 (the first endpoint) 12
The value of y1 (the first endpoint) 90
The value of x2 (the second endpoint) 45
The value of y2 (the second endpoint) 10
The midpoint of line is :
The midpoint's x value is: 28.5
The midpoint's y value is: 50.0
>>>
沒有留言:
張貼留言