2018年1月9日 星期二

Python: Calculate midpoints of a line

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

>>> 

沒有留言:

張貼留言

Node-Red --> MQTT --> Fuxa 開源碼網頁式圖控平台

Node-Red --> MQTT --> Fuxa      FUXA(一個開源的 Web HMI / SCADA 自動化監控軟體)的專案設定檔 。 這份設定檔完整定義了 HMI 監控畫面的 後端通訊(MQTT 連線、點位標籤) 與 前端網頁圖形介面(SVG 畫布...