## Determine if a patient has a cold or the flu def is_yes_or_no(string): new_string=input(string) if ((new_string == 'yes') or (new_string == 'Yes') or \ (new_string == 'YES') or (new_string == 'y') or (new_string == 'Y')): return (True) elif ((new_string == 'no') or (new_string == 'No') or \ (new_string == 'No') or (new_string == 'n') or (new_string == 'N')): return(False) else: print('''Your answer is not recognized as "yes" \ or "no", but I will assume that you intended to \ answer "no".''') return(False) def number_from_zero_to_ten (string): number = round(float(string)) if (number < 0): number = 0 elif (number > 10): number = 10 return(number) def check_for_swine_flu(): return(is_yes_or_no('Has the patient been \ vomiting or experiencing diarrhea?')) def main (): import time print('Welcome to the cold or flu program.') print('''If you suspect that the patient has either a cold or the flu, this program may be able to figure out which is more likely.''') print() print('''Please note that this program was created for demonstration purposes only. It's purpose is to illustrate what an expert system is. No doctor was consulted in the creation of this program. ********************************************* **PLEASE DO NOT USE THIS PROGRAM FOR MAKING** ********ACTUAL MEDICAL DECISIONS.************ ********************************************* The program loosely encodes the content of an article entitled,"Flu or Cold Symptoms?", which appeared at the following URL in the year 2011 http://www.webmd.com/cold-and-flu/cold-guide/flu-cold-symptoms WebMD, LLC is the copyright holder of that article.''') print() symptoms = 0 cold_symptoms = 0 flu_symptoms = 0 age = float(input('What is the age of the patient? ')) print() how_long = float(input('How many days has the patient been ill? ')) print() if (how_long > 7): flu_symptoms = 1 + flu_symptoms symptoms = 1 + symptoms if (is_yes_or_no('''Type "yes" if you have access to a thermometer or are able to find out the patient's temperature Type "no" if you cannot.''') == True): print() temperature = float(input('What is the patient\'s temperature in farenheit? ')) print() else: temperature = 98.6 print() if (temperature >= 99): symptoms = 1 + symptoms if ((temperature >= 99) and (temperature <= 100) \ and (age <= 16)): cold_symptoms = 1 + cold_symptoms fatigue_string = '''How tired is the patient? Type a number from 0 to 10, where 0 = normal level of tired, 5 is very tired, 8 is exhausted, and 10 is so tired that they can't leave the bed.''' fatigue_level = number_from_zero_to_ten\ (input(fatigue_string)) print() if (fatigue_level > 0): symptoms = 1 + symptoms if (fatigue_level > 3): flu_symptoms = 1 + flu_symptoms print('''Rate the following symptoms on a scale form 0 to 10, where 0 indicates that the patient does not have the symptom at all. 1 indicates the mildest form of the symptom, 5 indicates a high level, and 10 indicates a very extreme form.''') print() head_ache_level = number_from_zero_to_ten\ (input('Rate Patient\'s Headache or type 0 for no headache')) print() if (head_ache_level > 0): symptoms = 1 + symptoms flu_symptoms = 1 + flu_symptoms ache_level = number_from_zero_to_ten\ (input('Rate other aches and pains or type 0 for none')) print() if (ache_level > 0): symptoms = 1 + symptoms flu_symptoms = 1 + flu_symptoms cough_level = number_from_zero_to_ten\ (input('''Type 1 for mild chest discomfort, 2 for a mild cough, 5 for a moderately bad cough, all the way up to 10 for an uncontrollably nasty cough. Type 0 if there is no cough and no chest discomfort''')) print() if (cough_level > 0): symptoms = 1 + symptoms flu_symptoms = 1 + flu_symptoms print('Indicate the presense (yes) or absense (no) of the following symptoms') print() nasal = is_yes_or_no('Does the patient have a runny or stuffy nose? ') print() if nasal: symptoms = 1 + symptoms cold_symptoms = 1 + cold_symptoms sneezing = is_yes_or_no('Is the patient sneezing often?') print() if sneezing: symptoms = 1 + symptoms cold_symptoms = 1 + cold_symptoms sore_throat = is_yes_or_no('Does the patient have a sore throat?') print() if sore_throat: symptoms = 1 + symptoms cold_symptoms = 1 + cold_symptoms if (symptoms < 3): print('''The patient probably doesn\'t have cold or flu. The patient should consult a physician if they are sick''') elif ((fatigue_level > 6) or (temperature > 100)): if check_for_swine_flu(): print('''The patient probably has Swine Flu.''') else: print('''The patient probably has the Seasonal Flu.''') elif (cold_symptoms > flu_symptoms): print('''It is more likely that the patient has a cold, than the flu''') else: if check_for_swine_flu(): print('''The patient probably has Swine Flu.''') else: print('''It is more likely that the patient has the Seasonal Flu, than a cold''') time.sleep(5) main()