Sum a list · รวมรายการ
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.
รวมลิสต์
บวกทุกตัวเลขในลิสต์และ return ผลรวมทั้งหมด. เริ่มต้นผลรวมสะสมที่ 0, จากนั้นวนซ้ำผ่านลิสต์และเพิ่มแต่ละค่าเข้าไป
รูปแบบนี้ — ผลรวมสะสมที่เพิ่มขึ้นภายในลูป — ปรากฏทั่วไปในทุกการเขียนโปรแกรม
Write sum_list(xs) that returns the total of all numbers in the list xs. An empty list sums to 0. · เขียน sum_list(xs) ที่กลับค่าผลรวมของตัวเลขทั้งหมดใน list xs List ว่างรวมได้ 0
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่