如何使输出显示真/假?

时间:2017-12-18 22:46:37

标签: prolog

我的目标是在返回true

之前打印出falsemenu2/0的程序
park(_,blue,basketball_court).

menu2 :- 
    nl,write('Select operation:'),nl,
    write('1. Check which parking area available to park right now.'),nl,
    write('2. Check whether a particular parking area is legal to park.'),nl,
    write('3. End program.'),nl,
    read(X),nl,choice(X).

choice(2):-
    write('Enter your identity:'),nl,
    read(C),
    write('Enter sticker type:'),nl,
    read(D),
    write('Enter parking area:'),nl,
    read(E),
    park(C,D,E),
    menu2.

以下是我得到的:

menu2.

Select operation:
1. Check which parking area available to park right now.
2. Check whether a particular parking area is legal to park.
3. End program.
2

Enter your identity:
staff
Enter sticker type:
blue
Enter parking area:
basketball_court

Select operation:
1. Check which parking area available to park right now.
2. Check whether a particular parking area is legal to park.
3. End program.

basketball_court之后,我希望True出现。另外,在另一种情况下,即使出现'False',如何让它循环回menu2/0

1 个答案:

答案 0 :(得分:1)

以下是如何做到这一点:

choice(2):-
    write('Enter your identity:'),nl,
    read(C),
    write('Enter sticker type:'),nl,
    read(D),
    write('Enter parking area:'),nl,
    read(E),
    ( park(C,D,E) ->
      write('true'),nl
    ; write('false'),nl ),
    menu2.