-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem19.py
More file actions
21 lines (20 loc) · 784 Bytes
/
Copy pathProblem19.py
File metadata and controls
21 lines (20 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Problem19:
# Find an easy way to generate a list of "heads" and "tails"
# (use "H" and "T" chars) then store them in a list and output
# the number each side of a coin has been selected (used to
# verify how the random generators are working)
# Example output:
# Heads: 46
# Tails: 54
# import random module to use the random.choice method
import random
# create a list to be populated with results
coin_list = []
# run a for loop for predefined number of iterations - 100
for i in range(1, 101):
# append list with either "heads" or "tails" based on the
# random.choice method result for provided list: "H", "T"
coin_list += random.choice(["H", "T"])
# printout the result in agreed format
print("Heads: ", coin_list.count("H"))
print("Tails: ", coin_list.count("T"))