From 17f0af219bf536983d1dc52e773d9491df7c76b8 Mon Sep 17 00:00:00 2001 From: Serhii Berdianskyi Date: Fri, 27 Oct 2023 11:36:01 +0300 Subject: [PATCH] Wrote flip_coin function --- app/main.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index fa56336e..eba35852 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,18 @@ -# write your code here +import random + + +def flip_coin(): + num_simulations = 10000 + num_flips = 10 + results = {i: 0 for i in range(num_flips + 1)} + + for _ in range(num_simulations): + num_heads = sum(random.choice([0, 1]) for _ in range(num_flips)) + results[num_heads] += 1 + + percentage_results = {key: (value / num_simulations) * 100 for key, value in results.items()} + + return percentage_results + + +print(flip_coin())