【发布时间】:2016-02-24 23:46:10
【问题描述】:
尝试从用户输入中获取列表中的部分匹配项。
我正在尝试制作一个简单的诊断程序。用户输入他们的疾病,程序将输出建议的治疗方法。
print("What is wrong with you?")
answer=input()
answer=answer.lower()
problem=""
heat=["temperature","hot"]
cold=["freezing","cold"]
if answer in heat:
problem="heat"
if answer in cold:
problem="cold"
print("you have a problem with",problem)
我可以让它从列表中选择一个完全匹配,但我希望它从我的输入中找到部分匹配。例如,如果用户键入他们“太热了”。
【问题讨论】:
标签: list python-3.x