188k views
4 votes
You are to create a program using Python that asks the user for a nonnegative number, then computes the mean and variance using the above given online update formulas which should be displayed on the console screen. The program should end when a user enters a negative number.

User Ingalcala
by
5.4k points

1 Answer

3 votes

Answer:

# In the new version of python is available the functions mean() an variance()

# In the module of statistics

i = 0 #Var to input the elements

l = [] #Var to store the elements on a list

while(i>0):

print("In put a positive number to add in the list or negative to exit ")

i = input()

l.append(i)

print("The mean of the all elements is: " + mean(l) )

print("The variance of the all elements is: " + variance(i) )

Step-by-step explanation:

At present, you can use in the news python's verison e.g. (python 3.7) the statistics module and use functions like mean(), variance(), stdev() and many others.

In the first step you create two variables, i to recieve the inputs of a loop and l to store all the elements recieved in the i variable. after that you pass as an argument the list that you stored before and get the mean() and variance() of the all elements in the list.

I hope it's help you.

User Dodgrile
by
6.1k points