From 258db13f0f7313e902882e13f25d4fac6e73ca23 Mon Sep 17 00:00:00 2001 From: Serhii Fedorov Date: Mon, 23 Oct 2023 15:11:51 +0300 Subject: [PATCH 1/2] 'Solution' --- app/main.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index fa56336e..58f9cf4b 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,30 @@ -# write your code here +import random + +import matplotlib.pyplot as plt + + +def flip_coin() -> dict: + num_trials = 10000 + results = {i: 0 for i in range(11)} + + for _ in range(num_trials): + num_heads = sum(random.choice([0, 1]) for _ in range(10)) + results[num_heads] += 1 + + percentages = {key: (value / num_trials) * 100 + for key, value in results.items()} + return percentages + + +def draw_gaussian_distribution_graph(percentages: dict) -> None: + plt.bar(percentages.keys(), percentages.values()) + plt.xlabel("Number of Heads") + plt.ylabel("Percentage") + plt.title("Gaussian Distribution of Coin Flips") + plt.show() + + +if __name__ == "__main__": + percentages = flip_coin() + print(percentages) + draw_gaussian_distribution_graph(percentages) From 50779452dd5361ef645289175e9735bd80af520f Mon Sep 17 00:00:00 2001 From: Serhii Fedorov Date: Mon, 23 Oct 2023 15:16:38 +0300 Subject: [PATCH 2/2] Hiding matplotlib --- app/main.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/main.py b/app/main.py index 58f9cf4b..5f76b853 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,6 @@ import random -import matplotlib.pyplot as plt +# import matplotlib.pyplot as plt def flip_coin() -> dict: @@ -16,15 +16,15 @@ def flip_coin() -> dict: return percentages -def draw_gaussian_distribution_graph(percentages: dict) -> None: - plt.bar(percentages.keys(), percentages.values()) - plt.xlabel("Number of Heads") - plt.ylabel("Percentage") - plt.title("Gaussian Distribution of Coin Flips") - plt.show() - - -if __name__ == "__main__": - percentages = flip_coin() - print(percentages) - draw_gaussian_distribution_graph(percentages) +# def draw_gaussian_distribution_graph(percentages: dict) -> None: +# plt.bar(percentages.keys(), percentages.values()) +# plt.xlabel("Number of Heads") +# plt.ylabel("Percentage") +# plt.title("Gaussian Distribution of Coin Flips") +# plt.show() +# +# +# if __name__ == "__main__": +# percentages = flip_coin() +# print(percentages) +# draw_gaussian_distribution_graph(percentages)