目标: 在上面给出的代码中应用一个循环,这样它就会问:“你想继续吗? (是/否)“然后采取相应行动。 (提示:做一个谓词'再次/ 0'来执行上述任务)。
go:-
write('What is the name of Patient?'),
read(Patient),nl,
hypo(Patient, Disease),
write(Patient),
write(' probably has '),
write(Disease),nl.
go:-
write('Sorry I am unable to diagnose the Disease.'),nl.
hypo(Patient,flu):-
sym(Patient,fever),
sym(Patient,cough).
hypo(Patient,headche):-
sym(Patient,bodypain).
sym(Patient,fever):-
write(' Does '),
write(Patient),
write(' has fever (y/n)?'),
res(R), R='y'.
sym(Patient,cough):-
write('Does '),
write(Patient),
write(' has cough (y/n)?'),
res(R), R='y'.
sym(Patient,bodypain):-
write('Does '),
write(Patient),
write(' has bodypain (y/n)?'),
res(R), R='y'.
res(R):-
read(R),nl.
答案 0 :(得分:0)
您已经为模型提供了go
谓词。诀窍是,如果R='y'
没有失败,则通过递归再次调用谓词来获得循环。
again :-
write('Do you want to continue? (Y/ N)'),
res(R), R='y',
go,
again.
again :-
write('OK, bye'),nl.