So this might be a noob question, but how can I get a length of a list?
So I am calling the predicate “jogosGanhos(Team)” and it should return a list of all games a team won, then I want to use the length of that list to get the number of wins and divide by the total of games to get a win percentage. How can I do this?
My code looks like this:
winPercentage(Equipa):-
Wins is lenght(jogosGanhos(Equipa)),
P is Wins / 82,
format('\nA percentagem de vitórias da equipa '), write(Equipa),
format(' é '), write( P).
As the original poster (OP) to the topic you will get notifications. Others will not get automatic notifications unless you use @ with their tag, e.g. @c0rdeiro will cause you to get a notification. So if you want me to see a reply then please add @EricGT.
I think a key thing to understand is that the is thing is just for doing math. In general, predicates in Prolog don’t return values; instead, you use them to “unify” variables. It seems awkward (because, for instance, you can’t nest function calls), but can be very useful, because it lets you use the same predicate in a number of different ways!