- #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:
- Don't have a fever and don't have a stuffy nose: Hypochondriac
- Don't have a fever and have a stuffy nose: Head Cold
- Have a fever, don't have a rash, and ear hurts: Ear Infection
- Have a fever, don't have a rash, and ear doesn't hurt: Flu
- Have a fever and have a rash: Measles
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.