Prolog 人工智能语言中文论坛---打造优质Prolog学习交流园地
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Prolog 人工智能语言中文论坛---打造优质Prolog学习交流园地

一个供Prolog爱好者学习与交流的地方


您没有登录。 请登录注册

以prolog撰寫程式查詢小孩年齡

2 posters

向下  留言 [第1页/共1页]

1以prolog撰寫程式查詢小孩年齡 Empty 以prolog撰寫程式查詢小孩年齡 周三 十一月 21, 2012 6:46 am

Jessicaluin



Family(person(jack,fox,date(4,may,1960),work(class,180000)),
Person(susan,fox,date(8,may,1963),unemployed),[person(yoyo,fox,date(4,may,1987),
work(sales,80000)),person(mama,fox,date(7,may,1989),unemployed)]).



child_age :- child(father, mother, Child), write_age(father,mother).
child_age :- family(Parent, Child), write_age(Parent, _).

child_age(child,child ) :-
child= person(child_First_Name, child_Last_Name, date(D, M, Y), Work), Dad_Age is 2012 - Y,
write(child_First_Name), write(' '), write(child_last_name), write('. Age: '), write(child_Age), nl,
nonvar(Mom), Mom = person(child_first_name, child_last_Name, date(dd, mm, yy), ww), child_Age is 2012 - YY,
write(child_First_Name), write(' '), write(child_Last_Name), write('. Age: '), write(child_Age), nl, false.


請大大幫我糾正出程式不對的地方 謝謝 錯哪裡怎麼跑得出程式 謝謝

2以prolog撰寫程式查詢小孩年齡 Empty 回复: 以prolog撰寫程式查詢小孩年齡 周三 十一月 21, 2012 7:19 am

Mercury Liao


Admin

Jessicaluin 写道:Family(person(jack,fox,date(4,may,1960),work(class,180000)),
Person(susan,fox,date(8,may,1963),unemployed),[person(yoyo,fox,date(4,may,1987),
work(sales,80000)),person(mama,fox,date(7,may,1989),unemployed)]).



child_age :- child(father, mother, Child), write_age(father,mother).
child_age :- family(Parent, Child), write_age(Parent, _).

child_age(child,child ) :-
child= person(child_First_Name, child_Last_Name, date(D, M, Y), Work), Dad_Age is 2012 - Y,
write(child_First_Name), write(' '), write(child_last_name), write('. Age: '), write(child_Age), nl,
nonvar(Mom), Mom = person(child_first_name, child_last_Name, date(dd, mm, yy), ww), child_Age is 2012 - YY,
write(child_First_Name), write(' '), write(child_Last_Name), write('. Age: '), write(child_Age), nl, false.


請大大幫我糾正出程式不對的地方 謝謝 錯哪裡怎麼跑得出程式 謝謝

先随便看了一下,
有些比较明显的错误:

1. 定义事实的时候,Family、Person的大写都应改成小写,这里不应采用变量形式。
2. 没看到对write_age/2谓词的定义啊!
3. 没看到child/3、family/2的定义。

http://prolog.longluntan.net

3以prolog撰寫程式查詢小孩年齡 Empty 回复: 以prolog撰寫程式查詢小孩年齡 周三 十一月 21, 2012 7:54 am

Jessicaluin



family(person(jack,fox,date(4,may,1960),work(class,180000)),
person(susan,fox,date(8,may,1963),unemployed),[person(yoyo,fox,date(4,may,1987),work(sales,80000)),person(mama,fox,date(7,may,1989),unemployed)]).

例如這題~請問相對位置要怎麼修改~ 一樣查詢家庭小孩的年齡

謝謝你的回答

4以prolog撰寫程式查詢小孩年齡 Empty 回复: 以prolog撰寫程式查詢小孩年齡 周三 十一月 21, 2012 8:09 am

Jessicaluin



謝謝你ㄉ回答~ 如有問題我再問妳!!

5以prolog撰寫程式查詢小孩年齡 Empty 回复: 以prolog撰寫程式查詢小孩年齡 周三 十一月 21, 2012 8:24 am

Mercury Liao


Admin

Jessicaluin 写道:family(person(jack,fox,date(4,may,1960),work(class,180000)),
person(susan,fox,date(8,may,1963),unemployed),[person(yoyo,fox,date(4,may,1987),work(sales,80000)),person(mama,fox,date(7,may,1989),unemployed)]).

例如這題~請問相對位置要怎麼修改~ 一樣查詢家庭小孩的年齡

謝謝你的回答

关键还是看你想要什么,
虽然你想查询"家庭小孩的年龄",但是是在符合什么条件下的家庭小孩年龄?
如果是小孩无工作的,那一个小孩无工作一个有工作算不算?

这些描述清楚了,要解答你的问题肯定是很简单的。

http://prolog.longluntan.net

6以prolog撰寫程式查詢小孩年齡 Empty 回复: 以prolog撰寫程式查詢小孩年齡 周三 十一月 21, 2012 4:45 pm

Jessicaluin



Family(person(jack,fox,date(4,may,1960),work(class,180000)),
Person(susan,fox,date(8,may,1963),unemployed),[person(yoyo,fox,date(4,may,1987),
work(sales,80000)),person(mama,fox,date(7,may,1989),unemployed)]).
child_age:-child(father,mother,Child),write_age(father,mother).
child_age:-family(Parent,Child),write_age(Parent,_).
child_age(child,child ):-
child=person(child_First_Name,child_Last_Name,date(D, M, Y),Work),Dad_Ageis 2012-Y,
write(child_First_Name),write(' '),write(child_last_name),write('. Age: '),write(child_Age),nl,
nonvar(Mom), Mom = person(child_first_name,child_last_Name,date(dd, mm, yy),ww),child_Age is 2012-YY,
write(child_First_Name),write(' '),write(child_Last_Name),write('. Age: '),write(child_Age),nl,false.

還是沒辦法查詢小孩還缺哪些定義還是補需要補甚麼???

7以prolog撰寫程式查詢小孩年齡 Empty 回复: 以prolog撰寫程式查詢小孩年齡 周三 十一月 21, 2012 4:53 pm

Jessicaluin



Jessicaluin 写道:Family(person(jack,fox,date(4,may,1960),work(class,180000)),
Person(susan,fox,date(8,may,1963),unemployed),[person(yoyo,fox,date(4,may,1987),
work(sales,80000)),person(mama,fox,date(7,may,1989),unemployed)]).
child_age:-child(father,mother,Child),write_age(father,mother).
child_age:-family(Parent,Child),write_age(Parent,_).
child_age(child,child ):-
child=person(child_First_Name,child_Last_Name,date(D, M, Y),Work),Dad_Ageis 2012-Y,
write(child_First_Name),write(' '),write(child_last_name),write('. Age: '),write(child_Age),nl,
nonvar(Mom), Mom = person(child_first_name,child_last_Name,date(dd, mm, yy),ww),child_Age is 2012-YY,
write(child_First_Name),write(' '),write(child_Last_Name),write('. Age: '),write(child_Age),nl,false.

還是沒辦法查詢小孩還缺哪些定義還是補需要補甚麼???

只要有父母就要查詢到小孩年齡的意思不需要父母都有工作~

8以prolog撰寫程式查詢小孩年齡 Empty 回复: 以prolog撰寫程式查詢小孩年齡 周三 十一月 21, 2012 4:55 pm

Jessicaluin



Jessicaluin 写道:
Jessicaluin 写道:Family(person(jack,fox,date(4,may,1960),work(class,180000)),
Person(susan,fox,date(8,may,1963),unemployed),[person(yoyo,fox,date(4,may,1987),
work(sales,80000)),person(mama,fox,date(7,may,1989),unemployed)]).
child_age:-child(father,mother,Child),write_age(father,mother).
child_age:-family(Parent,Child),write_age(Parent,_).
child_age(child,child ):-
child=person(child_First_Name,child_Last_Name,date(D, M, Y),Work),Dad_Ageis 2012-Y,
write(child_First_Name),write(' '),write(child_last_name),write('. Age: '),write(child_Age),nl,
nonvar(Mom), Mom = person(child_first_name,child_last_Name,date(dd, mm, yy),ww),child_Age is 2012-YY,
write(child_First_Name),write(' '),write(child_Last_Name),write('. Age: '),write(child_Age),nl,false.

還是沒辦法查詢小孩還缺哪些定義還是補需要補甚麼???

只要有父母就要查詢到小孩年齡的意思不需要父母都有工作~

還是沒辦法查詢小孩年齡還缺哪些定義還是需要補些甚麼???

9以prolog撰寫程式查詢小孩年齡 Empty 回复: 以prolog撰寫程式查詢小孩年齡 周三 十一月 21, 2012 5:09 pm

Jessicaluin



Jessicaluin 写道:Family(person(jack,fox,date(4,may,1960),work(class,180000)),
Person(susan,fox,date(8,may,1963),unemployed),[person(yoyo,fox,date(4,may,1987),
work(sales,80000)),person(mama,fox,date(7,may,1989),unemployed)]).
child_age:-child(father,mother,Child),write_age(father,mother).
child_age:-family(Parent,Child),write_age(Parent,_).
child_age(child,child ):-
child=person(child_First_Name,child_Last_Name,date(D, M, Y),Work),Dad_Ageis 2012-Y,
write(child_First_Name),write(' '),write(child_last_name),write('. Age: '),write(child_Age),nl,
nonvar(Mom), Mom = person(child_first_name,child_last_Name,date(dd, mm, yy),ww),child_Age is 2012-YY,
write(child_First_Name),write(' '),write(child_Last_Name),write('. Age: '),write(child_Age),nl,false.

還是沒辦法查詢小孩還缺哪些定義還是補需要補甚麼???

教教我如何定義需要補上哪些東西~ 謝謝

10以prolog撰寫程式查詢小孩年齡 Empty 回复: 以prolog撰寫程式查詢小孩年齡 周四 十一月 22, 2012 3:02 am

Jessicaluin



[quote="Jessicaluin"][quote="Jessicaluin"]Family(person(jack,fox,date(4,may,1960),work(class,180000)),
Person(susan,fox,date(8,may,1963),unemployed),[person(yoyo,fox,date(4,may,1987),
work(sales,80000)),person(mama,fox,date(7,may,1989),unemployed)]).
child_age:-child(father,mother,Child),write_age(father,mother).
child_age:-family(Parent,Child),write_age(Parent,_).
child_age(child,child ):-
child=person(child_First_Name,child_Last_Name,date(D, M, Y),Work),Dad_Ageis 2012-Y,
write(child_First_Name),write(' '),write(child_last_name),write('. Age: '),write(child_Age),nl,
nonvar(Mom), Mom = person(child_first_name,child_last_Name,date(dd, mm, yy),ww),child_Age is 2012-YY,
write(child_First_Name),write(' '),write(child_Last_Name),write('. Age: '),write(child_Age),nl,false.

還是沒辦法查詢小孩還缺哪些定義還是補需要補甚麼???[/quote]

教教我如何定義需要補上哪些東西~ 謝謝[/quote]



程式跑出這個問題

ERROR: child_age/0: Undefined procedure: child/3
Exception: (7) child(father, mother, _G341) ?

要如何解決~

返回页首  留言 [第1页/共1页]

您在这个论坛的权限:
不能在这个论坛回复主题