Pls check my code,

i am assuming that when the input is zero then it is query asking for mean and std dev till that point and consecutive two zeros when we want to end the process

sum1 = 0
sum2 = 0
count = 0
x = int(input())
while x!= 0:
num = x
while num!= 0:
sum2 = sum2 + num2
sum1 = sum1 +num
num = int(input())
count = count+1
mean1 = sum1/count
mean2 = sum2/count
dev = np.sqrt(mean2 - mean1
2)
print(mean1)
print(dev)
x = int(input())

error:
1 2 0 0

ValueError Traceback (most recent call last)
in
2 sum2 = 0
3 count = 0
----> 4 x = int(input())
5 while x!= 0:
6 num = x

ValueError: invalid literal for int() with base 10: ‘1 2 0 0’

Basically input() function in python takes complete line at one time, this means that it is taking “1 2 0 0” as a single input string and that is the reason it is unable to convert it to the input.

So remember that always working in python input integers in separate line, so your input should be:
1
2
0
0

Now further work on logic for actual question, if you get stuck at any point, ask your doubt again.

1 Like

Got that point…
Can you check my code…its not giving any output…unable to figure out whats wrong…i am assuming when there is a zero in the input then the user wants to have mean and std dev till that point…and consectively two zeros then end of process…

Yes sure why not.

Actually you have used the function np.sqrt(), online ide doesn’t support numpy library so rather change that line to following line and your code would run fine.
dev = (mean2 - mean1 ** 2) ** (1/2)

Hope this cleared your doubt.
Happy Learning :blush:

1 Like

Yeah…thankyou :blush:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.