There are a couple of ways to do this. One way is:
1. Turn your integer into a string
2. Iterate through the string to get each digit
3. Turn each digit back into an integer
4a. Append these digits into an empty list, then sum(list)
4b. Or have a value similar to
total += digits
Rik Wittkopp While iterating through the string, if you can turn the digit to integer, why don't you just do the sum in there? I think there's no need to make a list of it since the OP only asking "How to calculate". Not saying that you're wrong but, you get what I mean.
Rik Wittkopp yeah, you can use generator expressions.👍
But you are doing some redundant operations(convert str to int then back to str)
You can write:
num = input() or "2345"
print(sum(int(i) for i in num))
print(sum(int(i) for i in input() or "2345").