Home› Python Programming Language› / Programs / Write Python programs that sum all the items in the list.
🚀 Programming Example

Write Python programs that sum all the items in the list.

214 Views
Beginner
Code Snippet

Write Python programs that sum all the items in the list.

💻 Program Code

def sum_oflist(items):
    sum_ofnumbers = 0
    for n in items:
        sum_ofnumbers += n
    return sum_ofnumbers

# function call
print(sum_oflist([1,2,-8]))

🖥 Program Output

                                -5
                            

📘 Explanation

📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.