Program:
road("A","B",200).
road("C","A",300).
road("B","C",100).
road("B","D",120).
road("C","D",130).
route(Town1 , Town2 , Distance):-road(Town1, Town2 , Distance).
route(Town1 , Town2 , Distance):-road(Town1, X , Distance1),route(X , Town2 , Distance2) , Distance is Distance1+Distance2,!.
Output-
Goal-Find the distance between A and B.
?- route("A", "B", Distance).
Distance = 200 ;
Distance = 800.
Goal-Find the distance between A and D.
?- route("A", "D", Distance).
Distance = 320.