语法错误
for count in (range(10)+1):
sum = 0 #存储累加的结果
# 进入for/in循环
for count in (range(10)+1): #1~10
sum += count #将数值累加
print('累加值:', sum) #输出累加的结果
错误结果:
Traceback (most recent call last):
File "F:/软件学习/Python/从零开始学Python程序设计/从零开始学Python - 范例程序/CH03/CH0331A.py", line 5, in <module>
for count in (range(10)+1): #0~10
TypeError: unsupported operand type(s) for +: 'range' and 'int'
可以改成
for i in range(1, 11):