The average() function is implemented in python so that when the variable parameter length is 0, the result can be returned correctly.

1. Subject requirements:

The average() function is implemented in python so that when the variable parameter length is 0, the result can be returned correctly.

2. Come and show:

# Enter a code
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)) 
print(average(1, 2, 2, 3, 4) )
print(average())

3. Operation results:

 I hope I can help everyone, I ask you if you want a like, will you give it, thank you all.
Copyright statement: The copyright of this article belongs to the author (@攻城狮小关) and CSDN. Welcome to reprint, but you must keep this paragraph without the author’s consent Statement, and provide the original link in an obvious place on the article page, otherwise the right to pursue legal responsibility is reserved.
It is not easy for everyone to write articles, please respect the fruits of labor~ 
Communication plus Q: 1909561302
Blog Park Address https://www.cnblogs.com/guanguan-com/

 

Guess you like

Origin blog.csdn.net/Mumaren6/article/details/108714327