-
Notifications
You must be signed in to change notification settings - Fork 55
/
Coin_Flipper.py
45 lines (37 loc) · 889 Bytes
/
Coin_Flipper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import random
def flip():
n = random.randint(0,1)
if n == 1:
return True
else:
return False
def user_prompt():
while True:
try:
userInput = input("Please enter a number of flips: ")
userInput = int(userInput)
if num_validity(userInput):
break
else:
print("Please Enter a valid Number which is more than 0")
except ValueError:
print("Please Enter a valid Number")
return userInput
def num_validity(flips):
return flips > 0
def main(num):
heads_count = 0
tails_count = 0
result= ""
for i in range(int(num)):
if (flip()):
heads_count+=1
result += "H "
else:
tails_count+=1
result += "T "
print("Number of Heads: %i" % (heads_count))
print("Number of Tails: %i" % (tails_count))
print(result)
Input = user_prompt()
main(Input)