Solve Python 3 Question Homework: Ear Infection Diagnosis

  • Thread starter DustyGeneral
  • Start date
  • Tags
    Python
In summary, DustyGeneral's program asks the user four questions about symptoms, and then says one of three things based on the answer to those questions.
  • #1
DustyGeneral
10
0

Homework Statement



You're going to create some medical diagnoses software. You are going to ask the user if they have a fever, a rash, if they have a stuffy nose, and if their ear hurts, and give one of the following responses:
  1. Don't have a fever and don't have a stuffy nose: Hypochondriac
  2. Don't have a fever and have a stuffy nose: Head Cold
  3. Have a fever, don't have a rash, and ear hurts: Ear Infection
  4. Have a fever, don't have a rash, and ear doesn't hurt: Flu
  5. Have a fever and have a rash: Measles
Sample output:
Do you have a fever? (y/n): y
Do you have a rash? (y/n): n
Does your ear hurt? (y/n): y
Diagnosis: You have an ear infection.

Note that the user should only ever have to enter lower case y or lower case n. Deviation from this will result in loss of points. The user will only ever enter 'y' or 'n', and you should ASK THE MINIMUM NUMBER OF QUESTIONS REQUIRED.

The Attempt at a Solution


[/B]
I have the program written so it asks all four questions (fever, rash, stuffy nose, and ear pain) all of the time and makes he diagnosis. For example for the sample output above in part 1 mine would say:

Do you have a fever? (y/n): y
Do you have a rash? (y/n): n
Does your ear hurt? (y/n): y
Do you have a stuffy nose? (y/n): (Input doesn't matter)
Diagnosis: You have an ear infection.

How would I go about telling it that if it has enough info to make a diagnosis to not ask any more questions. For example, if you put "y" for fever and "y" for rash it won't ask for ear pain and stuffy nose?

Here is what I have:def main ():

#User answers questions
fever = input("Do you have a fever? (y/n): ")
rash = input("Do you have a rash? (y/n): ")
ear = input("Does your ear hurt? (y/n): ")
nose = input("Do you have a stuffy nose? (y/n): ")

#Replies to the user about medical issues
if (fever == "n" and nose == "n"):
print("Diagnosis: You are a hypochondriac.")
elif (fever == "n" and nose =="y"):
print("Diagnosis: You have a head cold.")
elif (fever == "y" and rash == "n" and ear == "y"):
print("Diagnosis: You have an ear infection.")
elif (fever == "y" and rash == "n" and ear == "n"):
print("Diagnosis: You have the flu.")
elif (fever == "y" and rash == "y"):
print("Diagnosis: You have measles.")

main ()

Thanks in advance for your input.
 
Technology news on Phys.org
  • #2
Sorry about the spacing and conventions. In the program window all of the spacing and and indentations are correct.
 
  • #3
You should ask questions in the loop and after reading each single input you have to test the answers against known list of symptoms.

I feel like using simple system of == like you are trying to do goes against the flexibility of the Python and its built in data types (and makes later modifications a nightmare).

Best way of formatting code is with code tags. Sorry, can't show you how, I am getting Java errors ATM. System is still not 100% stable after the move.
 
  • #4
Borek said:
You should ask questions in the loop and after reading each single input you have to test the answers against known list of symptoms.
That's a bit overkill for this simple problem. It's easy to hand-construct a series of questions and responses that minimizes the number of questions to be asked. There's no need for a loop.

DustyGeneral, you need to ask questions in an order such that each question is pertinent to remaining possibilities. The order in which you ask questions is important. The optimal first question will do the best job of reducing the number of possible diagnoses by 1/2. With five diagnoses, you can't quite do that; the best you can do is eliminate two or three of the diagnoses. On the other hand, making stuffy nose the first question is a bad idea. This will eliminate at most one possibility.
 
  • #5


One way to solve this issue would be to use conditional statements to check if the user has already provided enough information to make a diagnosis. For example:

if fever == "y" and rash == "y":
print("Diagnosis: You have measles.")
elif fever == "y" and ear == "y":
print("Diagnosis: You have an ear infection.")
elif fever == "y" and ear == "n":
print("Diagnosis: You have the flu.")
elif fever == "n" and nose == "y":
print("Diagnosis: You have a head cold.")
elif fever == "n" and nose == "n":
print("Diagnosis: You are a hypochondriac.")

This way, if the user has already provided enough information (e.g. they have a fever and a rash), the program will skip over the other conditional statements and go straight to the appropriate diagnosis.
 

1. How can I use Python to diagnose ear infections?

To use Python for diagnosing ear infections, you will need to have a dataset of symptoms and corresponding diagnoses. You can use Python libraries such as Pandas and Scikit-learn to preprocess the data and create a machine learning model that can accurately predict ear infection diagnoses based on the given symptoms.

2. What kind of data do I need to input for the Python program to diagnose ear infections?

You will need to input a list of symptoms that the patient is experiencing, such as ear pain, fever, and discharge. The more specific and detailed the symptoms, the more accurate the diagnosis will be. It is also helpful to have data on the patient's age, medical history, and any previous ear infections.

3. How accurate is the ear infection diagnosis using Python?

The accuracy of the diagnosis will depend on the quality and quantity of the data used to train the machine learning model. With a large and diverse dataset, the accuracy can be high. However, it is always important to consult with a medical professional for an official diagnosis.

4. Can the Python program diagnose other types of ear problems?

Yes, the same program can be used to diagnose other ear problems such as swimmer's ear, otitis media, and earwax buildup. However, the accuracy may vary depending on the specific type of ear problem and the available data.

5. Do I need any prior coding experience to use this Python program for ear infection diagnosis?

Some basic knowledge of Python and machine learning concepts will be helpful in understanding and using the program. However, there are many tutorials and resources available online that can guide you through the process of using Python for medical diagnosis without prior coding experience.

Similar threads

  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
18
Views
2K
  • Biology and Medical
Replies
7
Views
2K
  • Programming and Computer Science
3
Replies
89
Views
4K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
17
Views
2K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
12
Views
3K
  • Programming and Computer Science
Replies
17
Views
2K
  • Programming and Computer Science
Replies
4
Views
2K
Back
Top