慕函数5470874
2022-06-15 13:18
我自己写的: 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))
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)) <-----需要在前面加* 才會接受tuple/list用法
Python3 入门教程(新版)
154167 学习 · 1075 问题
相似问题