用Python编写代码,从键盘中输入两个时间,一个航点间距,一个距平台距离自动求时间差的秒数,平均速度(航点间距/时间差),上一航点距离(时间差*平均速度),隐患问题距平台距离(距平台距离+上一航点距离),让程序一直在运行
时间: 2024-03-03 07:52:42 浏览: 14
好的,我可以帮你写出这样一个程序。这里使用Python的datetime模块来处理时间,用户输入的时间格式为"hh:mm:ss",航点间距和距平台距离的单位为米。请注意,本程序的计算结果可能受到用户输入的时间格式和数据精度的影响。
以下是代码实现:
```python
from datetime import datetime
while True:
# 获取用户输入的时间和距离数据
time1_str = input("请输入起始时间(格式为hh:mm:ss):")
time2_str = input("请输入结束时间(格式为hh:mm:ss):")
distance = float(input("请输入航点间距(单位为米):"))
platform_distance = float(input("请输入距平台距离(单位为米):"))
# 将时间字符串转换为datetiem对象
time1 = datetime.strptime(time1_str, "%H:%M:%S")
time2 = datetime.strptime(time2_str, "%H:%M:%S")
# 计算时间差
time_delta = (time2 - time1).total_seconds()
# 计算平均速度和上一航点距离
speed = distance / time_delta
last_distance = speed * time_delta
# 计算隐患问题距平台距离
danger_distance = platform_distance + last_distance
# 输出结果
print("时间差的秒数为:", time_delta)
print("平均速度为:", speed)
print("上一航点距离为:", last_distance)
print("隐患问题距平台距离为:", danger_distance)
```
运行程序后,用户可以输入起始时间、结束时间、航点间距和距平台距离,程序会输出计算结果,并等待用户输入下一组数据。程序会一直运行,直到用户手动停止。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)