In this example we will show how to calculate the sum of all numbers in a given list.
Source Code
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
n = input("Please input a number: ")
a = list(n)
sum = 0
for i in range(len(a)):
sum += int(a[i])
print("The sum is: ", sum)
Output:
Please input a number: 45623
The sum is: 20