From 947163887e328bdb7fdb15ec5a140533378cc2a5 Mon Sep 17 00:00:00 2001 From: Arsenii Aristov Date: Sun, 22 Dec 2024 20:42:30 +0200 Subject: [PATCH 1/2] Solution_coinflip --- app/main.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index fa56336e..e6e9e572 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,17 @@ -# write your code here +import random + + +def flip_coin() -> dict: + coin = ["heads", "tails"] + result = {} + for _ in range(10000): + num_of_heads = sum(random.choice(coin) == "heads" + for _ in range(10)) + + result[num_of_heads] = result.get(num_of_heads, 0) + 1 + + + for key, value in result.items(): + result[key] = round((value / 10_000) * 100, 2) + return dict(sorted((result.items()))) + From fee2c47843dc277bbc2512e4f6f162d70f50d690 Mon Sep 17 00:00:00 2001 From: Arsenii Aristov Date: Sun, 22 Dec 2024 20:46:04 +0200 Subject: [PATCH 2/2] Solution_coinflip --- app/main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/main.py b/app/main.py index e6e9e572..6358eccc 100644 --- a/app/main.py +++ b/app/main.py @@ -10,8 +10,6 @@ def flip_coin() -> dict: result[num_of_heads] = result.get(num_of_heads, 0) + 1 - for key, value in result.items(): result[key] = round((value / 10_000) * 100, 2) return dict(sorted((result.items()))) -