title: How to Calculate the average of an Existing list inside Knowledge base of prolog code?
body: <p>I have been trying for instance to have a list <code>[1,3]</code> and calculate its average inside the code without inputing the least itself. I'm not sure of the correct syntax to make it work, only the first line has a problem since it works perfectly fine if I called average and input the numbers when I run prolog.</p>
  
  <pre><code>average([1,3],X).
  
  
  average(List, Result) :- sum1(List, Len), sum(List, Sum), Result is Sum / Len.
  
  sum([], 0).
  
  sum([H|T], Sum) :- sum(T, Temp), Sum is Temp + H.
  
  
  sum1([],0).
  
  sum1([_|B],L):-sum1(B,Ln), L is Ln+1.
  </code></pre>