Lists (WSQ10 )

Hey there! We’ll be developing the WSQ10 assignment in this blogpost.

This code is not difficult but is longer than the rest. Here’s the description:

“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.”

Before we get started, let’s define the average and the standard deviation.

  1. Standard deviation: Is a measure that is used to quantify the amount of variation or dispersion of a set of data values. (Source: https://en.wikipedia.org/wiki/Standard_deviation)
  2.  Average: Is the sume of all the elements of a list divided by the number of elements.

Now, let’s start.

list01

We’ll build this code in three parts. The yellow one is about functions, the green one is the part that will ask the user for the 10 numbers and append them in a list, and the red one will print the results, calling the functions.

The first function is really easy, we just sum the elements form the list in line 20. The second function is the most difficult one. The formula to get the standard deviation, we need to compare each value with the total average, then square that sum, and at the end, divide everything by the number of elements on the list, in this case, 10.
The last function will be the average, we just sum all the elements divided by 10.

Line 27, 28 & 29 are going to call our three functions and print the results.

list02

Here are the results. The program asks the user correctly for 10 numbers and then the list gets printed. after that, as we were waiting, we get the total, the average and the standard deviation.

Here’s my code. If you have a suggestion about how to improve my code, pleas comment bellow.

Have a nice day!!!

Anuncios

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión /  Cambiar )

Google photo

Estás comentando usando tu cuenta de Google. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s