如何从方法列表中删除变量?

问题描述 投票:-1回答:2

我对Python相当陌生,我想知道如何解决问题。我正在进行基于文本的测验,以识别症状并确定您可能患有的疾病。我列出了一些包含症状的清单。然后,我针对每种疾病制定了一种方法(重复,我知道),以循环遍历症状并检查用户输入是否匹配。如果不是这样,我希望从可能的疾病列表中删除症状。但是请看,代码可以识别症状是否与第一个问题相匹配,但是即使将其删除,程序仍会在可能性列表中查找疾病。如果疾病不在可能的列表中,我尝试使用布尔变量来阻止程序循环。我试过使用可能的列表的for循环。我最近的尝试是将以前为Boolean的变量转换为字符串,然后以这种方式对其进行检查。就像我说的那样,我对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)

这里是错误:

追踪(最近一次通话):文件“ 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不在列表中

我对Python相当陌生,我想知道如何解决问题。我正在进行基于文本的测验,以识别症状并确定您可能患有的疾病。我做了几个...

python list variables deadlines
2个回答
0
投票

执行第一个ask()后打印“可能”列表,检查列表中是否仍存在“ Herpangina”


0
投票

如果您想为一位患者收集“是”和“否”,因为他们会回答是否有症状。并保持每种疾病的计数,您可以像这样遍历疾病/症状字典(symptom_dict)。

© www.soinside.com 2019 - 2024. All rights reserved.