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

>>> 

沒有留言:

張貼留言

MQTT WS HMI 與 Wokwi ESP32 連線的資訊透過HiveMQ

MQTT WS HMI 與 Wokwi ESP32 連線的資訊透過HiveMQ     https://console.hivemq.cloud/clusters 當您進入 HiveMQ Cloud Console 的 Clusters 頁面時,您的目標是取得能讓 MQTT W...