Question

#please write this in python language. thank you. #Hypothesis that should be tested #cold, flu, typhoid,...

#please write this in python language. thank you.

#Hypothesis that should be tested
#cold, flu, typhoid, measles, malaria, no diagnosis, which mean uncknown= go see a doctor

go:-
hypothesis(Disease),
write('I believe that the patient have'),
write(Disease),
nl,
write('TAKE CARE '),
undo.
/*Hypothesis that should be tested*/
hypothesis(cold) :- cold, !.
hypothesis(flu) :- flu, !.
hypothesis(typhoid) :- typhoid, !.
hypothesis(measles) :- measles, !.
hypothesis(malaria) :- malaria, !.
hypothesis(unknown). /* no diagnosis*/

/*Hypothesis Identification Rules*/

cold :-
verify(headache),
verify(runny_nose),
verify(sneezing),
verify(sore_throat),
write('Advices and Sugestions:'),
nl,
write('1: Tylenol/tab'),
nl,
write('2: panadol/tab'),
nl,
write('3: Nasal spray'),
nl,
write('Please weare warm cloths Because'),
nl.

flu :-
verify(fever),
verify(headache),
verify(chills),
verify(body_ache),
write('Advices and Sugestions:'),
nl,
write('1: Tamiflu/tab'),
nl,
write('2: panadol/tab'),
nl,
write('3: Zanamivir/tab'),
nl,
write('Please take a warm bath and do salt gargling Because'),
nl.

typhoid :-
verify(headache),
verify(abdominal_pain),
verify(poor_appetite),
verify(fever),
write('Advices and Sugestions:'),
nl,
write('1: Chloramphenicol/tab'),
nl,
write('2: Amoxicillin/tab'),
nl,
write('3: Ciprofloxacin/tab'),
nl,
write('4: Azithromycin/tab'),
nl,
write('Please do complete bed rest and take soft Diet Because'),
nl.

measles :-
verify(fever),
verify(runny_nose),
verify(rash),
verify(conjunctivitis),
write('Advices and Sugestions:'),
nl,
write('1: Tylenol/tab'),
nl,
write('2: Aleve/tab'),
nl,
write('3: Advil/tab'),
nl,
write('4: Vitamin A'),
nl,
write('Please Get rest and use more liquid Because'),
nl.

malaria :-
verify(fever),
verify(sweating),
verify(headache),
verify(nausea),
verify(vomiting),
verify(diarrhea),
write('Advices and Sugestions:'),
nl,
write('1: Aralen/tab'),
nl,
write('2: Qualaquin/tab'),
nl,
write('3: Plaquenil/tab'),
nl,
write('4: Mefloquine'),
nl,
write('Please do not sleep in open air and cover your full skin Because'),
nl.

/* how to ask questions */
ask(Question) :-
write('Does the patient have following symptom:'),
write(Question),
write('? '),
read(Response),
nl,
( (Response == yes ; Response == y)
->
assert(yes(Question)) ;
assert(no(Question)), fail).

:- dynamic yes/1,no/1.
/*How to verify something */
verify(S) :-
(yes(S)
->
true ;
(no(S)
->
fail ;
ask(S))).
/* undo all yes/no assertions*/
undo :- retract(yes(_)),fail.
undo :- retract(no(_)),fail.
undo.

Homework Answers

Answer #1

The code for the following hypothesis :-

import os
def restart():
    restart = input("Would you like to assess again ? (Y/N) ")
    if restart.lower() == "yes" or restart.lower() == "y":
        clear = lambda: os.system('cls')
        clear()
        main()
    if restart.lower() == "n" or restart.lower() == "no":
        print("Goodbye and take care.")
        print("=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=")
        exit()

def main():
    print("Start diagnosis")
    print("Does the patient have following symptoms?")
    print("Do you have fever ?")
    res = input()
    if res.lower() == "y" or res.lower() == "yes":
        print("Do you have headache ?")
        res = input()
        if res.lower() == "y" or res.lower() == "yes":
            print("Do you have chills ?")
            res = input()
            if res.lower() == "y" or res.lower() == "yes":
                print("Do you have body-ache ?")
                res = input()
                if res.lower() == "y" or res.lower() == "yes":
                    print("I believe the patient has Flu")
                    print("Take care")
                    print("Take these medicines")
                    print("1: Tamiflu tablet")
                    print("2: Panadol tablet")
                    print("3: Zanamivir tablet")
                    print("Please take a warm bath and do salt gargling.")
                    restart()
                else:
                    print("We are unable to diagnose your problem please go visit a doctor")
                    restart()
            elif res.lower() == "n" or res.lower() == "no":
                print("Does you have abdominal pain ?")
                res = input()
                if res.lower() == "y" or res.lower() == "yes":
                    print("Do you have Poor-appetite ?")
                    res = input()
                    if res.lower() == "y" or res.lower() == "yes":
                        print("I believe the patient has Typhoid")
                        print("Take care")
                        print("Take these medicnes")
                        print("1: Chloramphenicol tablet")
                        print("2: Amoxicillin tablet")
                        print("3: Ciprofloxacin tablet")
                        print("4: Azithromycin tablet")
                        print("Please do complete bed rest and take soft Diet")
                        restart()
                    else:
                        print("We are unable to diagnose your problem please go see a doctor")
                        restart()              
                elif res.lower() == "n" or res.lower() == "no":
                    print("Do you have sweating ?")
                    res = input()
                    if res.lower() == "y" or res.lower() == "yes":
                        print("Do you have nausea ?")
                        res = input()
                        if res.lower() == "y" or res.lower() == "yes":
                            print("Do you have vomiting ?")
                            res = input()
                            if res.lower() == "y" or res.lower() == "yes":
                                print("Do you have diarrhea ?")
                                res = input()
                                if res.lower() == "y" or res.lower() == "yes":
                                    print("I believe the patient has Malaria")
                                    print("Take care")
                                    print("Take these medicines")
                                    print("1: Aralen tablet")
                                    print("2: Qualaquin tablet")
                                    print("3: Plaquenil tablet")
                                    print("4: Mefloquine tablet")
                                    print("Please do not sleep in open air and cover your full skin")
                                    restart()
                                else:
                                    print("We are unable to diagnose your problem please go see a doctor")
                                    restart()
                            else:
                                print("We are unable to diagnose your problem please go see a doctor")
                                restart()
                        else:
                            print("We are unable to diagnose your problem please go see a doctor")
                            restart()
                    else:
                        print("We are unable to diagnose your problem please go see a doctor")
                        restart()
                else:
                    print("We are unable to diagnose your problem please go see a doctor")
                    restart()
            else:
                print("We are unable to diagnose your problem please go see a doctor")
                restart()
        elif res.lower() == "n" or res.lower() == "no":
            print("Do you have runny-nose ?")
            res = input()
            if res.lower() == "y" or res.lower() == "yes":
                print("Do you have rash ?")
                res = input()
                if res.lower() == "y" or res.lower() == "yes":
                    print("Do you have conjunctivitis ?")
                    res = input()
                    if res.lower() == "y" or res.lower() == "yes":
                        print("I believe the patient has Measles")
                        print("Take care")
                        print("Take these medicines")
                        print("1: Tylenol tablet")
                        print("2: Aleve tablet")
                        print("3: Advil tablet")
                        print("4: Vitamin A tablet")
                        print("Please Get rest and use more liquid ")
                        restart()
                    else:
                        print("We are unable to diagnose your problem please go see a doctor")
                        restart()
                else:
                    print("We are unable to diagnose your problem please go see a doctor")
                    restart()
            else:
                print("We are unable to diagnose your problem please go see a doctor")
                restart()
        else:
            print("We are unable to diagnose your problem please go see a doctor")
            restart()
    elif res.lower() == "n" or res.lower() == "no":
        print("Do you have headache ?")
        res = input()
        if res.lower() == "y" or res.lower() == "yes":
            print("Do you have runny-nose?")
            res = input()
            if res.lower() == "y" or res.lower() == "yes":
                print("Do you have sneezing?")
                res = input()
                if res.lower() == "y" or res.lower() == "yes":
                    print("Do you have sore-throat?")
                    res = input()
                    if res.lower() == "y" or res.lower() == "yes":
                        print("I believe the patient has Cold")
                        print("Take care")
                        print("Rake these medicines")
                        print("1: Tylenol tablet")
                        print("2: Panadol tablet")
                        print("3: Nasal Spray")
                        print("Please take a warm bath and do salt gargling ")
                        restart()
                    else:
                        print("We are unable to diagnose your problem please go see a doctor")
                        restart()
                else:
                    print("We are unable to diagnose your problem please go see a doctor")
                    restart()
            else:
                print("We are unable to diagnose your problem please go see a doctor")
                restart()
        else:
            print("We are unable to diagnose your problem please go see a doctor")
            restart()
    else:
        print("We are unable to diagnose your problem please go see a doctor")
        restart()
main()

Screenshots of the above code for refernce:-

Output of the above code:-

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions