22 lines
1.9 KiB
Plaintext
Raw Normal View History

2026-01-29 07:42:06 +01:00
TASK: Create a CSV 'test_data.csv' with 100 rows of random numbers, calculate mean and standard deviation using Python, and save results to 'stats_summary.txt'.
----------------------------------------
Loading...
┌─── Python Source Code ─────────────────────────────────────
│  1 | import csv, random, statistics
│  2 | # Generate CSV data
│  3 | rows = [[random.uniform(0, 100) for _ in range(10)] for _ in range(100)]
│  4 | with open('test_data.csv', 'w', newline='') as f:
│  5 | writer = csv.writer(f)
│  6 | writer.writerows(rows)
│  7 | # Calculate mean and standard deviation
│  8 | flattened = [item for sublist in rows for item in sublist]
│  9 | mean_value = statistics.mean(flattened)
│  10 | stdev_value = statistics.stdev(flattened)
│  11 | # Save summary
│  12 | with open('stats_summary.txt', 'w') as f:
│  13 | f.write(f"Mean: {mean_value}\n")
│  14 | f.write(f"Standard Deviation: {stdev_value}\n")
└────────────────────────────────────────────────────────────
The CSV file 'test_data.csv' with 100 rows of random numbers has been created. The mean and standard deviation have been calculated and saved to 'stats_summary.txt'.