my code's having a weird output - please help! | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 2

my code's having a weird output - please help!

https://code.sololearn.com/cxftd0OR8eqP i want the code to accept 5 numbers and output their sum, their average and their standard deviation. the sum and average look fine but the standard deviation is coming out with a long string of numbers for reference, this is how you find standard deviation https://www.mathsisfun.com/data/standard-deviation-formulas.html

27th Apr 2018, 4:09 PM
Jackson Meddows
Jackson Meddows - avatar
6 ответов
+ 1
SD = sqrt(1/n*sum(xi-mean)^2). you did not divide by n.
27th Apr 2018, 7:55 PM
yuri
+ 6
I think you should use a list (or better yet a numpy array) of numbers, instead of packing them in separate variables. Then you can easily calculate the things you want using simple loops and iterating through this list.
27th Apr 2018, 4:14 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
I'm not very good at loops though. I'm just trying to practice skills here, not actually produce a code so I'm trying to practice working with variables since I'm a bit inexperienced. Can you identify the issue with the method I already have? Thanks!
27th Apr 2018, 4:16 PM
Jackson Meddows
Jackson Meddows - avatar
+ 1
Or maybe you could help me with writing a code that uses a loop like you're talking about?
27th Apr 2018, 4:26 PM
Jackson Meddows
Jackson Meddows - avatar
0
I didn't know those libraries existed.... that helps a bit I guess since you were using a loop, but now I'm just really curious - why does my code output a weird number????
27th Apr 2018, 4:48 PM
Jackson Meddows
Jackson Meddows - avatar
0
Never mind, I fixed it! I was asking the program to take the square roots of the individual differences between the data points and the mean when I should have been asking for the square of said differences If that's confusing, here's a simplified version: I DONE GOOFED XD thanks for helping me guys!!
27th Apr 2018, 4:50 PM
Jackson Meddows
Jackson Meddows - avatar