'=+'
运算符给我一个错误的结果。与x =+ 3
相比,运行x = x + 3
返回错误的结果。我不确定原因。
from collections import namedtuple
BeltStats = namedtuple('BeltStats', 'score ninjas')
ninja_belts = {'yellow': BeltStats(50, 11),
'orange': BeltStats(100, 7),
'green': BeltStats(175, 1),
'blue': BeltStats(250, 5)}
def get_total_points_first (belts=ninja_belts):
total = 0
for belt in belts.values():
total =+ belt.score * belt.ninjas
return total #returns 1250, which is wrong
def get_total_points_second (belts=ninja_belts):
total = 0
for belt in belts.values():
product = belt.score * belt.ninjas
total = total + product
return total #returns 2675
我期望2675
,但使用运算符的输出为1250