From 2aa8f6d28eea2d992c86900f8c7aea0319ecaf2a Mon Sep 17 00:00:00 2001 From: Maks Vakulenko Date: Mon, 23 Dec 2024 22:11:12 +0100 Subject: [PATCH] solution --- app/main.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index fa56336e..8ba808b0 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,26 @@ -# write your code here +import matplotlib.pyplot as plt +import random + + +def flip_coin() -> dict: + result = {i: 0.0 for i in range(11)} + for _ in range(10000): + flip_res = [random.choice([0, 1]) for _ in range(10)] + head = sum(flip_res) + result[head] += 1 + + for key in result: + result[key] = round((result[key] / 10000) * 100, 2) + + return result + + +def draw_gaussian_distribution_graph(result: dict) -> None: + x_ = list(result.keys()) + y_ = list(result.values()) + + plt.plot(x_, y_) + plt.title("Gaussian Distribution") + plt.xlabel("Heads count") + plt.ylabel("Drop percentage") + plt.show()