两个问题,求高手回答
def average(*args): sum = 0 for x in args: sum = sum + x average = sum/len(args) print (average) print可以写在for循环外么?我试过写在for循环里会输出None 0.5 1.5 None 0.2 0.6 1.0 1.6 2.4 None 即输出了所有中间过程,可最后返回的为什么是none呢?
def average(*args): sum = 0 for x in args: sum = sum + x average = sum/len(args) print (average) print可以写在for循环外么?我试过写在for循环里会输出None 0.5 1.5 None 0.2 0.6 1.0 1.6 2.4 None 即输出了所有中间过程,可最后返回的为什么是none呢?
2017-08-04
举报