A Python project – A Basic Statistics Program
Lesson 6 of 15 · Python projects
In this project we will make a Python program that calculates basic statistical values for a set of numbers.
The program will calculate:
- the average
- the maximum value
- the minimum value
In this project we will use:
- lists
- loops
- built-in Python functions
- basic data analysis
An example of the program running
Enter numbers separated by spaces: 10 20 30 40 50
Average: 30.0
Minimum: 10
Maximum: 50
The program code
numbers_text = input("Enter numbers separated by spaces: ")
numbers = []
for n in numbers_text.split():
numbers.append(int(n))
average = sum(numbers) / len(numbers)
print("Average:", average)
print("Minimum:", min(numbers))
print("Maximum:", max(numbers))
How this code works
- input() takes a sequence of numbers
- split() splits the text into elements
- the numbers are converted into integer values
- we calculate the statistics with Python functions
You can extend the program by
calculating the median or the standard deviation.
Possible improvements to the project
- calculate the median
- calculate the standard deviation
- read the data from a CSV file
- show a chart
Next project
How to make the project your own:
1) first run the given code without changes, 2) change one thing and predict what will happen, 3) add at least one feature of your own, 4) write down in a notebook what you changed and why. A work log like that is the basis of a creative programming paper.
1) first run the given code without changes, 2) change one thing and predict what will happen, 3) add at least one feature of your own, 4) write down in a notebook what you changed and why. A work log like that is the basis of a creative programming paper.
