私はPythonが初めてで、これが機能しない理由を理解するのに苦労しています。
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)
基本的に、たとえばユーザーに 123 と入力して、1 と 2 と 3 の合計を取得してもらいます。
このエラーが発生しましたが、対処方法がわかりません。
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'
教科書でこれに対する答えを見つけることができず、2番目の for ループがリストを反復せず、値を合計に累積しない理由がわかりません。