I am new to Python and am having trouble wrapping my head around why this doesn't work.
number_string = input("Enter some numbers: ")
# Create List
number_list = [0]
# Create variable to use as accumulator
total = 0
# Use for loop to take single int from string and put in list
for num in number_string:
number_list.append(num)
# Sum the list
for value in number_list:
total += value
print(total)
Basically, I want a user to enter 123 for example and then get the sum of 1 and 2 and 3.
I am getting this error and do not know how to combat it.
Traceback (most recent call last):
File "/Users/nathanlakes/Desktop/Q12.py", line 15, in <module>
total += value
TypeError: unsupported operand type(s) for +=: 'int' and 'str'
I just can't find the answer to this in my textbook and don't understand why my second for loop won't iterate the list and accumulate the value to total.