基于Python开发一个时间编排系统,要求有批次时间、科目名称等。同时要求会自动检测批次的时间分为两种类型,一种是不低于90分钟、第二种事不低于120分钟,如果低于这两个时间会输出提示错误。每批次间隔时间为40分钟。
时间: 2024-05-05 13:15:31 浏览: 15
以下是一个示例代码,实现了一个简单的时间编排系统,包括输入批次时间和科目名称,以及自动检测批次时间是否符合要求,以及批次间隔时间的计算。
```
import datetime
MIN_TIME_1 = 90 # 批次最小时间1
MIN_TIME_2 = 120 # 批次最小时间2
INTERVAL = 40 # 批次间隔时间
def check_time(batch_time):
"""
检查批次时间是否符合要求
"""
if batch_time < MIN_TIME_1:
print("错误:批次时间不足90分钟")
return False
elif batch_time < MIN_TIME_2:
print("警告:批次时间不足120分钟")
return True
else:
return True
def input_schedule():
"""
输入时间编排表
"""
schedule = []
while True:
batch_time = input("请输入批次时间(分钟):")
if not batch_time:
break
try:
batch_time = int(batch_time)
except ValueError:
print("错误:输入的批次时间不是一个数字")
continue
if check_time(batch_time):
subject = input("请输入科目名称:")
schedule.append((batch_time, subject))
return schedule
def compute_schedule(schedule):
"""
计算时间编排表
"""
current_time = datetime.datetime.now()
for i, (batch_time, subject) in enumerate(schedule):
start_time = current_time + datetime.timedelta(minutes=i*(batch_time+INTERVAL))
end_time = start_time + datetime.timedelta(minutes=batch_time)
print(f"{start_time.strftime('%H:%M')} - {end_time.strftime('%H:%M')}: {subject}")
if __name__ == '__main__':
schedule = input_schedule()
compute_schedule(schedule)
```
运行示例:
```
请输入批次时间(分钟):80
错误:批次时间不足90分钟
请输入批次时间(分钟):100
请输入科目名称:语文
请输入批次时间(分钟):130
请输入科目名称:数学
请输入批次时间(分钟):110
请输入科目名称:英语
请输入批次时间(分钟):
20:06 - 21:46: 语文
21:26 - 23:46: 数学
23:06 - 01:06: 英语
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)