Sep-10-2023, 07:26 AM
So I was making a program to find the mean of a list entered by the user
My code:
And then I separated all of them using split()
Then I converted every element of the list into integer and added it into another list
Then I found the mean
My code:
Input =input("Please enter the data: ") Data = Input.split(",") Data1 = [] Length = len(Data1) Sum = sum(Data1) for x in Data: Data1.append(int(x)) Mean = Sum/Length print("The mean of ",Data1, "is ",Mean)First I asked the user for data in this format(1,2,7,89)
And then I separated all of them using split()
Then I converted every element of the list into integer and added it into another list
Then I found the mean
Error:Please enter the data: 1,2
Traceback (most recent call last):
Mean = Sum/Length
~~~^~~~~~~
ZeroDivisionError: division by zero