I am new to Python and I'm sure that I'm doing something wrong - I would like to ask a user for three numbers and print their sum, here's my current code:
for i in range(0, 3):
total = None
num = input('Please enter number {}:'.format(str(i)))
total += num
By the way, the total = None was to try and declare the variable so I could use it without setting a value?
I get this
Traceback (most recent call last):
File "<pyshell#20>", line 4, in <module>
total += num
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str'
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…