Answer
Answer
1. Write a program that list four addresses in a label form, each address
should list a name, one-line address, city, state & ZIP code. (Use for in
Answer :
% Define a person's information as a predicate
person(Name, Address, City, State, Zip) :-
write('Enter name: '), read(Name),
read(Address),
read(Zip).
write(Zip), nl)).
2. Write a program checking for Password.
A) Give an opportunity to user to re-enter the password „n‟ no. of Times,
on entering wrong password.
B) Give an opportunity to user to re-enter the password three (03)
Times, on entering wrong password.
Answer :
(A)
% Define the correct password password(secret).
).
read(Attempt),
check_password(Attempt).
(B)
% Define the correct password password(secret).
check_password(NewAttempt, NewTimesLeft);
check_password(Attempt, 3).
Answer :
% Main predicate to calculate the roots of a quadratic equation quadratic_roots(A,
B, C, X1, X2) :-
).
% Main predicate to take input from user and call the above predicate
main :- write('Enter the values of a, b, and c separated by spaces: '),
read(A), read(B), read(C), quadratic_roots(A, B, C, X1, X2).
4. Predict the Living organism from the given characteristics dataset.
Represent the characteristics of Living organism in form of predicates in
Prolog. You are supposed to make a question answering system, where the
questions to user be Example: Who many legs does your Living organism
have?
Characteristics of Animal: Generally Animals takes Nutrition by eating
herbs/bushes. They are having four legs. Animals generally have one
tail. They stay in cave. They have two eyes. They can breathe.
Characteristics of Birds: Birds eats worms and grains. They have one
beak. They have feathers. They can fly. They stay in nest. They have two
eyes. They can breathe
can_fly(B) :- B = bird.
takes_nutrition_from(P,
sunlight_water) :- P = plant.
color(P, green) :- P = plant.
% Define a predicate for answering questions about the characteristics of living organisms
characteristics(A, legs, X) :- legs(A, X).
Answer :
move(1, X, Y, _) :- write('Move disk
move(N, X, Y, Z) :-
N > 1,
M is N - 1,
move(M, X, Z, Y),
move(1, X, Y, _),
move(M, Z, Y, X).