-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ece647
commit 17f0af2
Showing
1 changed file
with
18 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) |