From fc0555e2118bc18207d8c11b81047b2a2a5c0849 Mon Sep 17 00:00:00 2001 From: Valdyslav Date: Wed, 18 Dec 2024 12:36:32 +0100 Subject: [PATCH] Solution --- app/main.py | 36 +++++++++++++++++++++++++++++++++++- requirements.txt | 3 +++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index fa56336e..c5a42199 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,35 @@ -# write your code here +import random +import matplotlib.pyplot as plt + + +def flip_coin() -> dict: + coin_seid = ["Head", "Tail"] + coin_chance_flip = {} + for game in range(10000): + heads_dropped_count = 0 + for flip in range(10): + if random.choice(coin_seid) == "Head": + heads_dropped_count += 1 + if heads_dropped_count in coin_chance_flip: + coin_chance_flip[heads_dropped_count] += 1 + else: + coin_chance_flip[heads_dropped_count] = 1 + for key, value in coin_chance_flip.items(): + coin_chance_flip[key] = round((value / 10000) * 100, 2) + return dict(sorted(coin_chance_flip.items())) + + +def draw_gaussian_distribution_graph() -> None: + coin_result = flip_coin() + x_points = [] + y_points = [] + for key, value in coin_result.items(): + y_points.append(int(key)) + x_points.append(value) + plt.plot(y_points, x_points) + plt.xlim(0, 10) + plt.ylim(0, 100) + plt.xlabel("Heads count") + plt.ylabel("Drop percentage %") + plt.show() + print(f"coin: {coin_result} \n y: {y_points} \n x: {x_points}") diff --git a/requirements.txt b/requirements.txt index 3f202d6e..d2f8b679 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,6 @@ flake8-quotes==3.3.1 flake8-variables-names==0.0.5 pep8-naming==0.13.2 pytest==7.1.3 + +matplotlib~=3.10.0 +numpy~=2.2.0 \ No newline at end of file