Compute Running Statistics Practice Problem
This data science coding problem helps you practice Functions & Scope, compute running statistics, and implementation skills. Read the problem statement, write your solution, and strengthen your understanding of Functions & Scope.
- Problem ID: 81
- Problem key: 81-compute-running-statistics
- URL: https://datacrack.app/solve/81-compute-running-statistics
- Difficulty: easy
- Topic: Functions & Scope
- Module: Python Fundamentals
Problem Statement
# 🧩 Compute Running Statistics
---
### 🎯 Goal
Computing summary statistics manually is a core skill. Before you reach for `df.describe()` or `np.mean()`, understanding how these values are computed from first principles makes you a better data scientist — especially when debugging unexpected results.
---
### 🔍 Statistics to Compute
| Statistic | Formula | Meaning |
|:----------|:--------|:--------|
| **count** | len(numbers) | How many values |
| **total** | sum of all values | The sum |
| **mean** | total / count | Average value |
| **minimum** | smallest value | Lower extreme |
| **maximum** | largest value | Upper extreme |
---
### 💻 Task
Implement `compute_stats(numbers)` **without** using built-in `sum()`, `min()`, `max()`, or `len()`.
---
### 📥 Input
- `numbers`: list of numbers — guaranteed non-empty
### 📤 Output
A dictionary with keys: `"count"`, `"total"`, `"mean"`, `"minimum"`, `"maximum"`
---
### 🧩 Starter Code
```python
def compute_stats(numbers):
"""
Compute basic descriptive statistics without using built-ins.
Args:
numbers (list): Non-empty list of numbers
Returns:
dict: {"count", "total", "mean", "minimum", "maximum"}
"""
# 🧠 TODO: Initialize count, total, min_val, max_val
# 🧠 TODO: Loop through numbers, updating each statistic
# 🧠 TODO: Compute mean = total / count
# 🧠 TODO: Return as a dictionary
pass
```
---
### 💡 Example
```python
compute_stats([4, 7, 2, 9, 1, 5])
# Expected: {"count": 6, "total": 28, "mean": 4.666..., "minimum": 1, "maximum": 9}
```
---
### 🔑 Key Concepts
- Initialize min/max with `numbers[0]`, not 0
- Build a dictionary `{}` and populate it with keys and values
- This is the manual version of `df.describe()` in PandasStarter Code
def compute_stats(numbers):
"""
Compute basic descriptive statistics without using built-ins.
Args:
numbers (list): Non-empty list of numbers
Returns:
dict: {"count", "total", "mean", "minimum", "maximum"}
"""
# 🧠 TODO: Initialize count, total, min_val, max_val
# 🧠 TODO: Loop through numbers, updating each statistic
# 🧠 TODO: Compute mean = total / count
# 🧠 TODO: Return as a dictionary
pass