Home > Back-end >  Missin part of func
Missin part of func

Time:01-21

Fill in the missing part of code:

def ______:
"""Returns the mean of all the numbers"""
total_sum = 0
n = len(x)
for i in x:
    total_sum = total_sum   i
return total_sum/n

print((mean(4, 5), mean(40, 45, 50)))

Output: (4.5, 45.0)

CodePudding user response:

def mean (*x):
"""Returns the mean of all the numbers"""
total_sum = 0
n = len(x)
for i in x:
    total_sum = total_sum   i
return total_sum/n
print((mean(4, 5), mean(40, 45, 50)))

CodePudding user response:

You can set your function name to anything you like. But it's seems you need to set it to mean.

def mean(*x):
   <rest of the code>

*x syntax is used to allow the function to take any number of arguments

If a Python function is not "valid" it means that it is not correctly written and will not run properly. This can happen for a variety of reasons, such as syntax errors, name errors, or logical errors.

Well, in all of these cases, the code will not run, and an error message will be displayed indicating what the problem is.

Your question format is wrong. You will probably be warned or banned by moderators if you do this too many times. So be careful! and welcome to Stack Overflow!

  • Related