为什么x = + 3对x = x + 3给出不同的答案?

时间:2019-07-10 08:26:42

标签: python operators

'=+'运算符给我一个错误的结果。与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

0 个答案:

没有答案