Question

Prolog newbie here. I have the following facts:

%marks(person, coursework_mark, exam_mark)
marks( julie, 77, 63).
marks( pete, 55, 21).
marks( chris, 69, 53).
marks( samantha, 68, 42).
marks( james, 79, 73).

and would like to write a rule that gives me the persons total mark if coursework_mark counts for 25% of the overall grade and exam_mark counts for the remaining 75%.

I've tried:

got_perc(Person,Perc):-marks(Person((_X*0.25)+(_Y*0.75)).

Please can anyone help? Thank you.

Était-ce utile?

La solution

As lurker pointed out in his comment, you will need to use the is/2 standard built-in predicate to make the calculations. Something like:

got_perc(Person, Perc) :-
    % get student work and exam grades
    marks(Person, Work, Exam),
    % calculate the student final grade  
    Perc is Work*0.25 + Exam*0.75.

The is/2 standard built-in predicate, which is also defined as an infix operator, unifies the left operand with the result of evaluating the right operand as an arithmetic expression.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top