Professional Documents
Culture Documents
Prolog 1 Studs v2
Prolog 1 Studs v2
PROLOG: LAB 1
likes(mary,tennis).
likes(boris,football).
likes(boris,tennis).
likes(erica,swim).
Example 1:
?- likes(mary,tennis).
Every query must start with a “?-“ and ends with a period character “.”
Simple query can only give “yes” or “no” as a response
Example 1:
?- likes(mary,What).
Example 2:
?- likes(mary,_).
?- likes(boris,tennis),likes(mary,tennis).
?- likes(boris,A),likes(mary,A).
Try these..
Question 1
Miss Azlina teaches CSC305 and CSC258. Mr. Ali teaches CSC318 and CSC258.
Which of the following is the CORRECT prolog fact related to the above statement?
A. teaches(azlina,csc305).
teaches(azlina,csc258).
teaches(ali,csc318).
teaches(ali,csc258).
B. teaches(azlina,csc305,csc258).
teaches(ali,csc318,csc258).
C. teachers(azlina,ali).
subjects(csc258,csc305, csc318).
D. teacher(azlina) :- subjects(csc305,csc258).
teacher(ali) :- subjects(csc318,csc258).
Question 2
speaks(boris,russian).
speaks(john,english).
speaks(mary,russian).
speaks(mary,english).
Question 3
a) Based on the given table, convert the English statements into facts in Prolog:
Food/beverage Price(RM)
Beriyani Rice 18.00
Kebab 10.00
Nan Set 25.00
Iced Tea 2.50
Iced Milo 3.00
c) Write a query to find out which food/beverage is RM18.00? State the output as well.
d) Write a query that will list down all the foods/beverages with prices below than RM15.00. State the output as well.
c) ?- food_price(Food, 18.00).
Food = 'Beriyani Rice'.
Question 4
ticketPrice(packageOne,55).
ticketPrice(packageTwo,75).
ticketPrice(packageThree,110).
b) Write a query that will display all the packages with fee less than RM80.
d) Write a query that will display the name of the package which has price more than RM70 but less than RM100.
a) i. Y = 55.
ii. Output:
```
X = packageThree.
```
iii. No output will be generated because there is no package with a price of 85 in the given facts.
c) Package = packageOne,
Price = 55 ;
Package = packageTwo,
Price = 75.