Исправил незначительные ошибки

This commit is contained in:
2026-09-08 09:02:57 +03:00
parent 843a6a1c12
commit efcd862cf8
3 changed files with 16 additions and 9 deletions

7
data.txt Normal file
View File

@@ -0,0 +1,7 @@
1
93
0
0.12
-111
123
4

View File

@@ -17,8 +17,10 @@ def main() -> None:
"--top", type=int, default=5, help="Number of largest values to display"
)
parser.add_argument(
"--min-len", type=float, default=0.0,
help="Minimum value to include (numbers below are ignored)"
"--min-len",
type=float,
default=None,
help="Minimum value to include (numbers below are ignored). If not set, all numbers are included.",
)
parser.add_argument(
"--format", choices=["text", "json"], default="text",
@@ -45,7 +47,6 @@ def main() -> None:
sys.exit(1)
if args.format == "json":
# convert numbers to strings or keep as is; JSON serializable
output = {
"count": stats["count"],
"sum": stats["sum"],

View File

@@ -1,7 +1,7 @@
"""Core functions for numeric analysis."""
from pathlib import Path
from typing import List, Tuple, Optional
from typing import List, Optional
def read_numbers(
@@ -25,7 +25,7 @@ def read_numbers(
if min_value is None or val >= min_value:
numbers.append(val)
except ValueError:
# skip nonnumeric lines (per requirement, we can ignore them)
# skip nonnumeric lines
continue
return numbers
@@ -33,7 +33,7 @@ def read_numbers(
def analyze_numbers(
file_path: Path,
top_n: int = 5,
min_len: int = 0, # used as minimum numeric value
min_len: Optional[float] = None, # теперь None по умолчанию
encoding: str = "utf-8",
) -> dict:
"""
@@ -45,9 +45,9 @@ def analyze_numbers(
- mean: arithmetic mean
- min: minimum value
- max: maximum value
- top: list of (value, count?) or just values? We'll return top N largest numbers.
- top: list of N largest numbers
"""
numbers = read_numbers(file_path, encoding=encoding, min_value=float(min_len))
numbers = read_numbers(file_path, encoding=encoding, min_value=min_len)
if not numbers:
return {
"count": 0,
@@ -63,7 +63,6 @@ def analyze_numbers(
mean = total / count
min_val = min(numbers)
max_val = max(numbers)
# top N largest numbers (if top_n > 0)
top_values = sorted(numbers, reverse=True)[:top_n]
return {