Exercise 1
Your task is to write a Python script to do the following:
- Read data from the file
prog_data.txt
into a list.
- Note: Data in this file comes from the course survey. The numbers represent the level of programming confidence that students had coming into the course on a scale of 1 to 5.
- Using the
enumerate
build-in type, perform a for
loop to convert elements in the list from ints to floats.
- Remember that data will be read in as a string type. You will do calculations which require floats. To convert from a string to a float just do float(string). However, note that this only works sometimes: How to convert data types in Python 3. It will work in our current use case.
- Using the
Counter
method from the collections
library, determine what the most common number in your list is.
- Hint: You will need to access the first element of the list returned by the
Counter
method.
- Print out the following for the user:
- Total number of respondents (suggestions: use the
len
function)
- Maximum number in the list (suggestion: use the
max
function)
- Minimum number in the list (suggestion: use the
min
function)
- Median of list (suggestion: use
numpy
--- look up median in numpy
)
- Mean of list (suggestion: use
numpy
--- look up mean in numpy
)
- Most common number in list with number of times it occurs.
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.