我有一个模块列表,可以执行几个不同的功能,如math.py、time.py、date.py和weather.py。我想使用用户输入从列表中适当地选择答案,例如,如果用户今天输入日期,则运行date.py模块,如果另一个输入是"现在几点?"teh-time.py模块运行。它应该作为一个连续的循环运行。请帮忙这是样本代码
import sys
import math
from dates import date
import weather
Mymodule-List = ['math','weather','date']
words = input ('Please enter your query: ').lower()
words2 = words[:]
while True
for item in words2:
statement
………#这就是我被卡住的地方
我需要一些来自模块的内容,并说:"时间是上午11:50。谢谢"输入"现在是什么时间"等
如果我理解正确:
import importlib
def run_func(module_name)
importlib.import_module(module_name)
# some code...
# ... some code ... while ...
if name in ['math','weather','date']:
run_func(name)