Selasa, 08 Desember 2009

Input Output in Prolog (Loop) : exercise

Exercise 1
Define a predicate to output the values of the squares of the integers from N1 to N2 inclusive and test it with N1 = 6 and N2 = 12.

First, write down the code, and save as .pl file. For this exercise, we will save it as squares.pl


Open Prolog, click File>Consult and find the file that you saved. Prolog will manage to show you a successful quote just like the screenshot show.

write down this : square(8,16).
and the result will be like this :

and done ... :)

Exercise 2
Define and test a predicate to read in a series of characters input by the user and output all of those before the first new line or ? character.

First, write down the code, and save as .pl file. For this exercise, we will save it as number2.pl

Open Prolog, click File>Consult and find the file that you saved. Prolog will manage to show you a successful quote just like the screenshot show.

write down this : start.
hit enter and write the words that you want. and hit enter again.
the result will be like this :



and done .. :)

Exercise 3 
Using the person clauses given in Section 6.3.1, find the professions of all those over 40.
First, write down the code, and save as .pl file. For this exercise, we will save it as person.pl



Open Prolog, click File>Consult and find the file that you saved. Prolog will manage to show you a successful quote just like the screenshot show.


write down this : find.
and the result will be like this : 

and done .. :)

okey .. the Final Project Week 6 is done. hope this tutorial can gives you a inspiration.
if you have any question, plese feel free to ask me !! just by leave comments fellaaas. thanks.

see you soon ..  


0 comments:

Posting Komentar