Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

CSC305: TOPIC 4

Total questions: 15

Worksheet time: 6mins

Name
Class
Date
1.

Logic programming is also known as declarative programming.

a)

True

b)

False

2.

Ruby is one of the major programming languages for logic programming.

a)

False

b)

True

3.

A Horn Clause has a head and a body.

a)

True

b)

False

4.

Resolution happens when the system fails to prove a sub-goal or sub-query.

a)

False

b)

True

5.

A term in Prolog can exist in THREE (3) forms:

a)

constant

b)

data type

c)

structure

d)

query

e)

variable

6.

Choose a statement that is FALSE about Prolog.

a)

A Prolog term is an atom, a variable, a numeric value or a structure.

b)

A variable is any string of letters, digits and underscores that begins with a lowercase letter.

c)

Atoms are symbolic values of Prolog.

d)

Structures represent the composite value of Prolog.

7.

Given the following Prolog statements, identify the control structure used.


calcDistance(D1, D2, Distance):-

( D1 > D2, Distance is D1-D2, !;

D2 > D1, Distance is D2 - D1, !;

Distance is 0).

a)

Multiple-selection statements

b)

One-way selection statements

c)

Three-way statements

d)

Two-way selection statements

8.

The Prolog query given below is an example of a(n) _____ query.


?- append([1,2],[b,c],Z).

a)

anonymous

b)

goal

c)

simple

d)

variable

9.

Analyze the following Prolog facts about totalfees for a day care center for kids.


totalfees(15, halfday, 200).

totalfees(15, fullday, 350).

totalfees(20, halfday, 250).

totalfees(20, fullday, 400).


What will be the output if you run the following query?


?- totalfees(Day, halfday, Total), Day > 15.

a)

Day = 15, Total 200.

b)

Day = 15, Total = 350.

c)

Day = 20, Total = 250.

d)

Day = 20, Total = 400.

10.

Based on the given database in Prolog, which of the following queries will yield TRUE?


parent(tiffany, lisa).

parent(tiffany, lily).

parent(brian, lisa).

parent(brian, lily).


sibling(X,Y) :- parent(Z, X), parent(Z, Y).

a)

?- parent(tiffany, brian).

b)

?- sibling(lisa, lily).

c)

?- sibling(tiffany, lisa).

d)

?- sister(lisa, lily).

11.

Based on the given rules and facts in Prolog, which of the following queries will yields FALSE only as answer?


score(ali, 90).

score(amy, 75).

score(abu, 45).

a)

score(ali, _).

b)

score(_, 60).

c)

score(abu,X).

d)

score(A,B).

12.

In logic programming languages, the basic form of statement can be constructed as follows EXCEPT _____.

a)

fact statements

b)

declaration statements

c)

rule statements

d)

goal statements

13.

Discover the correct meaning of the following Prolog rule.


sibling (X, Y) : -

mother(M,X) ,mother(M,Y) ,father(F,X) ,father(F,Y) ,not(X=Y).

a)

X and Y are different people

b)

M is a mother of Y

c)

F is not a father of Y

d)

Fis a father of X

14.

Examine the Prolog expressions below that is/are syntactically true.

a)

father(azmi,ali).

b)

parent (wati, qaisara) :- mother(wati,qaisara).

c)

?- sibling(X,amir).

d)

define parent :- parent (X, Y) .

15.

Based on the given fact below:


p ( [X1x2] ,X1,X2) .


What will be the output for this query?


?- p( [ [ orange,mango] ,banana,watermelon,kiwi] ,H,T) .

a)

X1 = orange,

X2 = [mango, banana, watermelon, kiwi]

b)

X1 =[orange,mango],

X2 = [banana, watermelon, kiwi]

c)

H =[orange, mango] ,

T = [banana, watermelon, kiwi]

d)

H = orange,mango,

T = banana, watermelon, kiwi