这哪里错了?,报错: unsupported operand type(s) for +=: 'int' and 'tuple'(+=:“int”和“tuple”的操作数类型不受支持)
我自己写的: def average(*args): b = 0 if len(args) == 0: return b else: for i in args: b += i avg = b / len(args) return avg a=(1, 2, 3, 4, 5) print(average(a))
参考答案:
def average(*args): sum = 0 if len(args) == 0: return sum for item in args: sum += item avg = sum / len(args) return avg a=(1, 2, 3, 4, 5) print(average(a))