我对 Python 还很陌生,我想知道如何解决问题。我正在做一个基于文本的测验,以识别症状并确定您可能患有哪种疾病。我列出了几个包含症状的清单。然后我为每种疾病制定了一个方法(重复-我知道),循环检查症状并检查用户输入是否匹配。如果没有,我希望将症状从可能的疾病列表中删除。但是请注意,代码可以识别症状是否与第一个问题相匹配,但是即使在将其删除后,该程序仍会在可能性列表中查找该疾病。如果疾病不在可能的列表中,我尝试使用布尔变量来阻止程序循环。我尝试使用带有可能列表的 for 循环。我最近的尝试将以前的布尔变量变成了字符串并以这种方式检查它们。就像我说的,我对 Python 还很陌生,所以如果这是一个简单的错误,我很抱歉。如果你能帮忙,请做!该项目将于周五到期。太感谢了!
这是代码(对不起,如果这太长了。Python新手-网站新手!):
possibles = [ "InfluenzaA", "InfluenzaB", "InfluenzaC", "CommonCold", "Pneumonia", "StrepThroat", "b", "n", "Croup", "EnterovirusD68", "h", "Herpangina", "PinkEye", "Pertussis"]
InfluenzaA = ["Cough", "Runny nose" "Stuffy nose", "Sneezing", "Sorethroat", "Fever", "Headache", "Bodychills", "Fatigue", "Body aches"]
CommonCold = ["Cough", "Runny nose" "Stuffy nose", "Sneezing", "Sorethroat", "Fever", "Headache", "Bodychills", "Fatigue", "Body aches"]
InfluenzaB = ["Cough", "Stuffy nose", "Sore throat", "Fever", "Headache", "Body chills", "Fatigue", "Muscle aches", "Nausea", "Vomiting"]
InfluenzaC = ["Cough", "Rhinorrhea", "Fever", "Headache", "Muscle pain" ]
CommonCold = ["Cough", "Runny nose", "Stuffy nose", "Congestion", "Sneezing","Sore throat", "Fever", "Headache", "Malaise"]
Pneumonia = ["Cough", "Chest pain", "Fever", "Fatigue", "Loss of appetite", "Body pain", "Shortness of breath", "Fast heartbeat"]
StrepThroat = ["Fever", "Headache", "Throat pain", "Loss of appetite", "Nausea", "Vomiting", "White dots", "Red dots", "Inability or diffuculty swallowing"]
Bronchiolitis = ["Cough", "Runny nose", "Stuffy nose", "Fever", "Shortness of breath", "Wheezing", "Ear pain", "Loss of fluids"]
Norovirus = ["Fever", "Abdominal pain", "Malaise", "Muscle pain", "Diarrhea", "Nausea", "Vomiting"]
Croup = ["Cough", "Runny nose", "Stuffy nose", "Shortness of breath", "Wheezing", "Sore throat", "Fever", "Throat pain", "Fatigue"]
EnterovirusD68 = ["Cough", "Runny nose", "Stuffy nose", "Sneezing", "Wheezing", "Fever", "Body aches"]
HandFootandMouthDisease = ["Sore throat", "Fever", "Headache", "Fatigue","Rash", "Drooling"]
Herpangina = ["Sore throat", "Fever", "Headache", "Fatigue", "Loss of appetite", "Inabilty or diffuculty swallowing", "Mouth blisters or ulcers", "Drooling", "Vomiting"]
PinkEye = ["Red eye", "Eye discharge", "Blurred vision", "Light sensitivity"]
Pertussis = ["Cough", "Runny nose", "Stuffy nose", "Fever", "Fatigue", "Vomiting", "Mucus in the throat"]
stinA = "yes"
stinBe = "yes"
stinC = "yes"
stinPer = "yes"
stinHM = "yes"
stinH = "yes"
stinE = "yes"
stinN = "yes"
stinPE = "yes"
stinCr = "yes"
stinCC = "yes"
stinST = "yes"
def cycleInfluenzaA(sy, stinA):
for i in range(len(InfluenzaA)):
if InfluenzaA[i].upper() == sy.upper():
return
possibles.remove("InfluenzaA")
stinA = "no"
(其余格式相同)
def ask(bod, stinCC, stinCr, stinE, stinA, stinC, stinBe, stinH, stinN, stinPer, stinPE):
sy = input("Have you experienced any symptoms relation to your " + bod + "\n")
if stinCC == "yes":
cycleCold(sy, stinCC)
(其余格式相同)
print("Welcome to this medical database. This is an interactive test to determine what illness a taker may be suffering from. Let's begin.")
ask("chest", stinCC, stinCr, stinE, stinA, stinC, stinBe, stinH, stinN, stinPer, stinPE)
ask("throat", stinCC, stinCr, stinE, stinA, stinC, stinBe, stinH, stinN, stinPer, stinPE)
这是错误:
Traceback(最近一次调用最后一次):文件“main.py”,第 150 行,在
问(“喉咙”,stinCC,stinCr,stinE,stinA,stinC,stinBe,stinH,stinN,stinPer,stinPE)
文件“main.py”,第 140 行,询问
cycleHerpangina(sy, stinH)
文件“main.py”,第 100 行,在 cycleHerpangina 中
possibles.remove("Herpangina")
ValueError: list.remove(x): x 不在列表中