python 代码讨论
def average(*args):
sum = 0
n = 0
for x in args:
if n != None:
sum = sum + x
n = n + 1.0
if n != 0:
return sum/n
else:
return 0.0
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
#斜体部分改成 n = n + 1 为什么不对
def average(*args):
sum = 0
n = 0
for x in args:
if n != None:
sum = sum + x
n = n + 1.0
if n != 0:
return sum/n
else:
return 0.0
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
#斜体部分改成 n = n + 1 为什么不对
2017-05-14
举报