请问average()按照答案写的,但是最后算的平均值不对,这是怎么回事呢
def average(*args):
sum = 0
if len(args) == 0:
return sum
for item in args:
sum += item
avg = sum / len(args)
return avg
print(average(1,2,2,3,4))
算出来的答案是2
def average(*args):
sum = 0
if len(args) == 0:
return sum
for item in args:
sum += item
avg = sum / len(args)
return avg
print(average(1,2,2,3,4))
算出来的答案是2
2023-12-12
举报