From 440fc5b70169f23d8fa703860a54ce1f1e51ff6e Mon Sep 17 00:00:00 2001 From: Serhiy Date: Wed, 4 Dec 2024 00:29:01 +0200 Subject: [PATCH 1/5] Solution --- app/main.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index fa56336e..b8406c3e 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,38 @@ -# write your code here +import random + +import matplotlib.pyplot as plt + + +def flip_coin() -> dict: + numbers = [[random.randint(0, 1) for _ in range(10)] + for _ in range(1, 10001)] + sum_numbers = [sum(number) for number in numbers] + dict_numbers = {"0": sum_numbers.count(0) / 10000 * 100, + "1": sum_numbers.count(1) / 10000 * 100, + "2": sum_numbers.count(2) / 10000 * 100, + "3": sum_numbers.count(3) / 10000 * 100, + "4": sum_numbers.count(4) / 10000 * 100, + "5": sum_numbers.count(5) / 10000 * 100, + "6": sum_numbers.count(6) / 10000 * 100, + "7": sum_numbers.count(7) / 10000 * 100, + "8": sum_numbers.count(8) / 10000 * 100, + "9": sum_numbers.count(9) / 10000 * 100, + "10": sum_numbers.count(10) / 10000 * 100} + return dict_numbers + + +def draw_gaussian_distribution_graph(coins: dict, + title: str = "Gaussian distribution", + x_label: str = "Head count", + y_label: str = "Drop percents %") -> None: + x_values = list(coins.keys()) + y_values = list(coins.values()) + plt.plot(x_values, y_values) + plt.title(title) + plt.xlabel(x_label) + plt.ylabel(y_label) + plt.show() + + +coin = flip_coin() +draw_gaussian_distribution_graph(coin) From bb70032779964d09e8d131c0bc57266159ead50f Mon Sep 17 00:00:00 2001 From: Serhiy Date: Wed, 4 Dec 2024 00:35:03 +0200 Subject: [PATCH 2/5] added module matlotlib --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index b8406c3e..031f0b44 100644 --- a/app/main.py +++ b/app/main.py @@ -1,5 +1,5 @@ import random - +import matplotlib import matplotlib.pyplot as plt From f8654f8953a26287d716be77326f9a769bc3b813 Mon Sep 17 00:00:00 2001 From: Serhiy Date: Wed, 4 Dec 2024 00:36:29 +0200 Subject: [PATCH 3/5] deleted import matlotlib --- app/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app/main.py b/app/main.py index 031f0b44..68f53144 100644 --- a/app/main.py +++ b/app/main.py @@ -1,5 +1,4 @@ import random -import matplotlib import matplotlib.pyplot as plt From 8ab8bc2b776aa6d3fe441e690e4f6c67698de70f Mon Sep 17 00:00:00 2001 From: Serhiy Date: Wed, 4 Dec 2024 00:39:20 +0200 Subject: [PATCH 4/5] added matlotlib --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 3f202d6e..893067e7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ flake8-quotes==3.3.1 flake8-variables-names==0.0.5 pep8-naming==0.13.2 pytest==7.1.3 +matplotlib From dd95d1eb5e82c7919986921258e2309c87770cc3 Mon Sep 17 00:00:00 2001 From: Serhiy Date: Wed, 4 Dec 2024 00:44:41 +0200 Subject: [PATCH 5/5] Solution --- app/main.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/main.py b/app/main.py index 68f53144..8128c28a 100644 --- a/app/main.py +++ b/app/main.py @@ -6,17 +6,17 @@ def flip_coin() -> dict: numbers = [[random.randint(0, 1) for _ in range(10)] for _ in range(1, 10001)] sum_numbers = [sum(number) for number in numbers] - dict_numbers = {"0": sum_numbers.count(0) / 10000 * 100, - "1": sum_numbers.count(1) / 10000 * 100, - "2": sum_numbers.count(2) / 10000 * 100, - "3": sum_numbers.count(3) / 10000 * 100, - "4": sum_numbers.count(4) / 10000 * 100, - "5": sum_numbers.count(5) / 10000 * 100, - "6": sum_numbers.count(6) / 10000 * 100, - "7": sum_numbers.count(7) / 10000 * 100, - "8": sum_numbers.count(8) / 10000 * 100, - "9": sum_numbers.count(9) / 10000 * 100, - "10": sum_numbers.count(10) / 10000 * 100} + dict_numbers = {0: sum_numbers.count(0) / 10000 * 100, + 1: sum_numbers.count(1) / 10000 * 100, + 2: sum_numbers.count(2) / 10000 * 100, + 3: sum_numbers.count(3) / 10000 * 100, + 4: sum_numbers.count(4) / 10000 * 100, + 5: sum_numbers.count(5) / 10000 * 100, + 6: sum_numbers.count(6) / 10000 * 100, + 7: sum_numbers.count(7) / 10000 * 100, + 8: sum_numbers.count(8) / 10000 * 100, + 9: sum_numbers.count(9) / 10000 * 100, + 10: sum_numbers.count(10) / 10000 * 100} return dict_numbers