martes, 7 de marzo de 2017

Lists

Lists (#WSQ07)
For our WSQ07 task we were asked to 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.




But what is a list?
Well, a list is created by placing all the items (elements) inside a square bracket [ ], separated by commas. It can have any number of items and they may be of different types (integer, float, string etc.).
Also with lists, in python we have many "List methods" that are like some type of functions you can use inside lists, like adding more elements to it or to remove some.
Here´s a list with the main list methods you can use:
Table got from: https://www.programiz.com/python-programming/list

Here´s my code so you can check it out on your own text editor:
list =[]
while True:
    x = input("Please add numbers to the list. Whe you finish type "'done'":" )
    if x == "done":
        break
    else:
        list.append(float(x))
total=0
for i in list:
    total += i
print ("The total is:", total )
average= total/(len(list))
print ("The average is:", average)
step=0
for i in list:
    step += ((i-average)**2)
stdev= step/(len(list))
standardDeviation = stdev**(1/2)
print ("The Satndard Deviation is:", standardDeviation)

I found a very good video in my classmate´s blog: elusblog.wordpress.com

No hay comentarios:

Publicar un comentario