30 lines
773 B
Python
30 lines
773 B
Python
#!/usr/bin/env python3
|
|
"""Process numbers from a file and output statistics."""
|
|
|
|
import sys
|
|
|
|
def main():
|
|
filepath = sys.argv[1] if len(sys.argv) > 1 else "numbers.txt"
|
|
|
|
# Read numbers from file
|
|
with open(filepath, 'r') as f:
|
|
content = f.read()
|
|
|
|
numbers = [int(x) for x in content.strip().split('\n') if x.strip()]
|
|
|
|
# Calculate statistics
|
|
total = sum(numbers)
|
|
count = len(numbers)
|
|
avg = total / count if count > 0 else 0
|
|
minimum = min(numbers) if numbers else 0
|
|
maximum = max(numbers) if numbers else 0
|
|
|
|
# Output results
|
|
print(f"Sum: {total}")
|
|
print(f"Count: {count}")
|
|
print(f"Average: {avg:.2f}")
|
|
print(f"Min: {minimum}")
|
|
print(f"Max: {maximum}")
|
|
|
|
if __name__ == "__main__":
|
|
main() |