Fixes.
This commit is contained in:
+15
-12
@@ -3,16 +3,19 @@ TASK: Create a CSV 'test_data.csv' with 100 rows of random numbers, calculate me
|
||||
Loading...
|
||||
|
||||
[1;34m┌─── Python Source Code ─────────────────────────────────────[0m
|
||||
[1;34m│[0m [2m 1 |[0m [34mimport[0m[33m random[0m
|
||||
[1;34m│[0m [2m 2 |[0m [34mimport[0m[33m statistics[0m
|
||||
[1;34m│[0m [2m 3 |[0m # Generate [36m100[0m[33m rows of random numbers[0m
|
||||
[1;34m│[0m [2m 4 |[0m data = [random.random() [34mfor[0m[33m _ in range([36m100[0m[33m)][0m
|
||||
[1;34m│[0m [2m 5 |[0m # Calculate mean and standard deviation[0m
|
||||
[1;34m│[0m [2m 6 |[0m mean_value = statistics.mean(data)[0m
|
||||
[1;34m│[0m [2m 7 |[0m std_dev = statistics.stdev(data)[0m
|
||||
[1;34m│[0m [2m 8 |[0m # Save results to a file[0m
|
||||
[1;34m│[0m [2m 9 |[0m [34mwith[0m[33m open('stats_summary.txt', 'w') [34mas[0m[33m f:[0m
|
||||
[1;34m│[0m [2m 10 |[0m f.write(f'Mean: {mean_value}\n')[0m
|
||||
[1;34m│[0m [2m 11 |[0m f.write(f'Standard Deviation: {std_dev}\n')[0m
|
||||
[1;34m│[0m [2m 1 |[0m [34mimport[0m[33m csv, random, statistics[0m
|
||||
[1;34m│[0m [2m 2 |[0m # Generate CSV data[0m
|
||||
[1;34m│[0m [2m 3 |[0m rows = [[random.uniform([36m0[0m[33m, [36m100[0m[33m) [34mfor[0m[33m _ in range([36m10[0m[33m)] [34mfor[0m[33m _ in range([36m100[0m[33m)][0m
|
||||
[1;34m│[0m [2m 4 |[0m [34mwith[0m[33m open('test_data.csv', 'w', newline='') [34mas[0m[33m f:[0m
|
||||
[1;34m│[0m [2m 5 |[0m writer = csv.writer(f)[0m
|
||||
[1;34m│[0m [2m 6 |[0m writer.writerows(rows)[0m
|
||||
[1;34m│[0m [2m 7 |[0m # Calculate mean and standard deviation[0m
|
||||
[1;34m│[0m [2m 8 |[0m flat_list = [item [34mfor[0m[33m sublist in rows [34mfor[0m[33m item in sublist][0m
|
||||
[1;34m│[0m [2m 9 |[0m mean_value = statistics.mean(flat_list)[0m
|
||||
[1;34m│[0m [2m 10 |[0m std_dev = statistics.stdev(flat_list)[0m
|
||||
[1;34m│[0m [2m 11 |[0m # Save results[0m
|
||||
[1;34m│[0m [2m 12 |[0m [34mwith[0m[33m open('stats_summary.txt', 'w') [34mas[0m[33m f:[0m
|
||||
[1;34m│[0m [2m 13 |[0m f.write(f'Mean: {mean_value}\n')[0m
|
||||
[1;34m│[0m [2m 14 |[0m f.write(f'Standard Deviation: {std_dev}\n')[0m
|
||||
[1;34m└────────────────────────────────────────────────────────────[0m
|
||||
The CSV file with 100 rows of random numbers has been generated, and the mean and standard deviation have been calculated and saved to 'stats_summary.txt'.
|
||||
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'.
|
||||
|
||||
Reference in New Issue
Block a user