Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
oorrja
GitHub Repository: oorrja/learntosolveit
Path: blob/master/languages/python/algorithm_toss_coins.py
1240 views
1
# Example showing tossing of coins
2
3
import random
4
5
heads = tails = count = 0
6
choice = ''
7
8
while choice.lower() != 'q':
9
count = count + 1
10
choice = random.choice(["heads","tails"])
11
if choice == "heads":
12
heads = heads + 1
13
else:
14
tails = tails + 1
15
print(choice)
16
choice = input("Press any key to continue or q to quit")
17
18
print('Total :', count)
19
print('Heads :', str(heads), ' Percentage ', ((heads * 1.0)/count) * 100)
20
print('Tails :', str(tails), ' Percentage ', ((tails * 1.0)/count) * 100)
21
22