From 121f65f7fe79198d284a9bf7085d29f61dacde25 Mon Sep 17 00:00:00 2001 From: el chibuk Date: Tue, 16 Jan 2024 14:59:58 +0200 Subject: [PATCH 1/3] Solution --- app/main.py | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index fa56336e..a2011275 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,37 @@ -# write your code here +import random +import matplotlib.pyplot as plt + + +def flip_coin() -> dict: + statistics = {} + + for test in range(10000): + heads_count = 0 + + for attempt in range(10): + if random.choice(["tails", "heads"]) == "heads": + heads_count += 1 + + if heads_count not in statistics: + statistics[heads_count] = 1 / 10000 * 100 + else: + statistics[heads_count] += 1 / 10000 * 100 + + return {key: round(statistics[key], 2) for key in range(11)} + + +# ----------------Graph creation---------------- + + +flip_stats = flip_coin() + +heads_number = [i for i in range(11)] +probability = [value for value in flip_stats.values()] + +plt.plot(heads_number, probability) +plt.xticks(heads_number, size=8) +plt.ylabel("Drop percentage, %") +plt.xlabel("Heads count") +plt.grid() + +plt.show() From 9d9efb32bd28ac3f0e47d0ab6e0607ae23259af3 Mon Sep 17 00:00:00 2001 From: el chibuk Date: Tue, 16 Jan 2024 15:03:43 +0200 Subject: [PATCH 2/3] added matplotlib --- requirements.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/requirements.txt b/requirements.txt index 3f202d6e..a43b6bf6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,5 @@ flake8-quotes==3.3.1 flake8-variables-names==0.0.5 pep8-naming==0.13.2 pytest==7.1.3 + +matplotlib~=3.8.2 \ No newline at end of file From 6820f5cdcf12e4a382183d7a24e7bb7aaf237c84 Mon Sep 17 00:00:00 2001 From: el chibuk Date: Tue, 16 Jan 2024 15:05:28 +0200 Subject: [PATCH 3/3] fixed draw func --- app/main.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/app/main.py b/app/main.py index a2011275..2297e52f 100644 --- a/app/main.py +++ b/app/main.py @@ -22,16 +22,14 @@ def flip_coin() -> dict: # ----------------Graph creation---------------- +def draw_gaussian_distribution_graph(data: dict) -> None: + heads_number = [i for i in range(11)] + probability = [value for value in data.values()] -flip_stats = flip_coin() + plt.plot(heads_number, probability) + plt.xticks(heads_number, size=8) + plt.ylabel("Drop percentage, %") + plt.xlabel("Heads count") + plt.grid() -heads_number = [i for i in range(11)] -probability = [value for value in flip_stats.values()] - -plt.plot(heads_number, probability) -plt.xticks(heads_number, size=8) -plt.ylabel("Drop percentage, %") -plt.xlabel("Heads count") -plt.grid() - -plt.show() + plt.show()