Hello,
Today I´m going to show you a new code. Every new code has a new level of complexity and this one is not the exception.
Instructions:
Create a program that asks the user for 10 numbers (floating point). Store those numbers in a list. Show to the user the total, average and standard deviation of those numbers.
Well, as you cans see, we are going to apply some of the information that we used in the past, like the sum and the average of a range of numbers, but, now we have to use the deviation. Let me explain what is the deviation of a range of numbers.
This is the formula:
(http://geographyfieldwork.com/StandardDeviation1.htm)
Now, knowing what is a standard Deviation we can the the code and this is my code:
First, we need create a function for the sum of the numbers.
Second, we have to create another function for the average of all the range of numbers.
The last two mentioned steps doesn’t have any problem because we analized how to do it in the last posts. On the other hand, for the deviation you only need to follow the rules of the formula and the rules of math, it isn’t hard.
NOTES:
- Use float.
- As you can see I’m using another kind of loop, it is called FOR LOOP and basically it is like a while loop but in other order.
Syntax of a for loop:
for ( init; condition; increment ) { statement(s); }
- The init step is executed first, and only once.