Skip to content
How to Compute Min, Max, and Average in Python with Simple Code
Fundamentals 4 min read

How to Compute Min, Max, and Average in Python with Simple Code

This article walks through a Python tutorial that generates a random list, sorts it, and calculates the minimum, maximum, sum, and average values, providing clear explanations, code snippets, and output screenshots for readers to follow along.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining

Introduction

Hello, I'm a Python enthusiast. Yesterday a community member asked a basic Python question about calculating statistics such as the average.

Solution

The idea is to use the definition of average; the code below generates a random list, sorts it, and computes the minimum, maximum, sum, and average.

Another contributor offered an alternative approach.

Final implementation:

import random
data = random.choices(range(1, 20), k=10)
new_data = sorted(data)
the_min = new_data[0]
the_max = new_data[-1]
the_sum = 0
for i in data:
    the_sum += i
the_average = the_sum / len(data)
print(f'生成的随机列表是{data}
排序后的列表是{new_data}
最小值是{the_min},最大值是{the_max},和是{the_sum},平均值是{the_average}')

Running the script produces the expected results.

The problem required sorting, so using sorted is acceptable.

Conclusion

The article demonstrates how to solve a typical Excel‑style data‑processing task in Python, providing clear explanation and complete code for readers to apply.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

data processingstatisticsCode Tutorialaverage
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.