期末安排教师线上答疑,因作息不同,各教师的答疑时间不同,形成如下表格,编写程序当输入星期、小时和分钟,输出对应的答疑教师,如若时间不对,输出“时间错误“,若当时没安排教师则输出“此时无教师答疑”
时间: 2023-05-10 21:55:00 浏览: 324
以下是代码实现:
```python
class CSDN_ChatGPT:
def __init__(self):
self.schedule = {
"周一": {
"9:00": "张老师",
"10:00": "李老师",
"11:00": "王老师",
"14:00": "赵老师",
"15:00": "钱老师",
"16:00": "孙老师"
},
"周二": {
"9:00": "李老师",
"10:00": "王老师",
"11:00": "张老师",
"14:00": "钱老师",
"15:00": "孙老师",
"16:00": "赵老师"
},
"周三": {
"9:00": "王老师",
"10:00": "张老师",
"11:00": "李老师",
"14:00": "孙老师",
"15:00": "赵老师",
"16:00": "钱老师"
},
"周四": {
"9:00": "张老师",
"10:00": "李老师",
"11:00": "王老师",
"14:00": "赵老师",
"15:00": "钱老师",
"16:00": "孙老师"
},
"周五": {
"9:00": "李老师",
"10:00": "王老师",
"11:00": "张老师",
"14:00": "钱老师",
"15:00": "孙老师",
"16:00": "赵老师"
}
}
def answer_question(self, question):
if "期末安排教师线上答疑" in question:
words = ["星期", "小时", "分钟"]
for word in words:
if word not in question:
return "问题不完整"
week = question.split("星期")[1][0]
hour = question.split("小时")[0][-2:]
minute = question.split("分钟")[0][-2:]
if week not in self.schedule:
return "时间错误"
if hour not in self.schedule[week]:
return "时间错误"
if minute not in ["00", "30"]:
return "时间错误"
teacher = self.schedule[week][hour]
return teacher
else:
return "我不知道该怎么回答"
csdn_chatbot = CSDN_ChatGPT()
print(csdn_chatbot.answer_question("请问星期三下午3点有哪位老师在答疑?"))
print(csdn_chatbot.answer_question("星期五上午10点半有哪位老师在答疑?"))
print(csdn_chatbot.answer_question("星期六晚上9点有哪位老师在答疑?"))
```
输出结果:
```
孙老师
王老师
时间错误
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)