Week 4 Prolog
Week 4 Prolog
WAP in turbo prolog for medical diagnosis and show the advantages and
disadvantages of green and red cuts.
goonce :-
write("What is the patient's name? "),nl,
readln(Patient),
hypothesis(Patient,Disease),!,
write(Patient),write(" probably has "),
write(Disease),nl,
go;
write("Sorry, I am not in a position to diagnose the disease."), go.
symptom(Patient, fever):-
write("Does"),write(Patient),write(" have a fever (y/n)? "), nl,
response(Reply),
Reply = 'y'.
symptom(Patient, rash):-
write("Does "), write(Patient), write(" have a rash (y/n)? "), nl,
response(Reply),
Reply = 'y'.
symptom(Patient, body_ache):-
write("Does "), write(Patient), write(" have a body ache (y/n)? "), nl,
response(Reply),
Reply = 'y'.
symptom(Patient, runny_nose):-
write("Does "), write(Patient), write(" have a runny nose (y/n)? "), nl,
response(Reply),
Reply = 'y'.
hypothesis(Patient, flu) :-
symptom(Patient, fever),
symptom(Patient, body_ache),
symptom(Patient, rash),
symptom(Patient, runny_nose).
hypothesis(Patient, common_cold) :-
symptom(Patient, body_ache),
symptom(Patient, runny_nose).
response(Reply) :-
read(Reply).
go:-
write("Would you like to try again (y/n)? "),
response(Reply),
Reply = 'y',
goonce.
OUTPUT:-