Sum a list · Sommer une liste
Sum a list
Add up every number in a list and return the total. Start a running total at 0, then loop over the list and add each value to it.
This pattern — a running total that grows inside a loop — comes up everywhere in programming.
Sommer une liste
Additionnez tous les nombres d'une liste et retournez le total. Commencez un total cumulé à 0, puis bouclez sur la liste et ajoutez chaque valeur.
Ce motif — un total cumulé qui croît dans une boucle — apparaît partout en programmation.
Write sum_list(xs) that returns the total of all numbers in the list xs. An empty list sums to 0. · Écrivez sum_list(xs) qui retourne la somme de tous les nombres dans la liste xs. Une liste vide donne une somme de 0.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.