Your task is to write a Python script to do the following:
prog_data.txt into a list.enumerate build-in type, perform a for loop to convert elements in the list from ints to floats.Counter method from the collections library, determine what the most common number in your list is.Counter method.len function)max function)min function)numpy --- look up median in numpy)numpy --- look up mean in numpy)Note: Please don't write a function to do this. A script is sufficient for this exercise. We'll get to functions soon.
Your output should look something like:
The total number of respondants is 45.
The maximum programming confidence is 5.0.
The minimum programming confidence is 1.0.
The median programming level is 4.0.
The mean programming level is 3.4.
The most common programming level is 4.0 with 17 respondants.
In [1]:
f=open("prog_data.txt","r")
text=f.read()
text_clean=text.replace("\n","")
f.close()
print(text_clean)
type(text_clean)
Out[1]:
In [31]:
import collections
float_list=[];
for j in text_clean:
float_list.append(float(j))
print(float_list)
In [30]:
how_many = collections.Counter(float_list)
print(how_many)
In [40]:
import numpy as np
print("The total number of respondants is",len(float_list))
print("The maximum programming confidence is",max(float_list))
print("The minimum programming confidence is",min(float_list))
print("The median programming level is",np.median(float_list))
print("Mean of list",np.mean(float_list))
print("Most common number in list with number of times it occurs",how_many.most_common(1))
In [ ]: