-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflip.py
102 lines (54 loc) · 1.86 KB
/
flip.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import tkinter as tk
import random
import time
from turtle import color
import matplotlib
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import matplotlib.pyplot as plt
root = tk.Tk()
root.title("COIN FLIPPER")
root.resizable(0,0)
root.geometry('500x550')
frame = tk.Frame(root)
frame.pack()
choices = ['Head', 'Tail']
def plot():
pass
def start():
flips =[]
flip_range = int(entry.get())
for x in range(flip_range):
result = random.choice(choices)
flips.append(result)
head_percentage = round(flips.count("Head")/len(flips)*100,5)
tail_percentage = round(flips.count("Tail")/len(flips)*100,5)
heads['text'] = "Head Percentage is " + str(head_percentage)+"%"
tails['text'] = "Tail Percentage is " + str(tail_percentage) +"%"
data = {
'head': head_percentage,
'tail': tail_percentage
}
titles = list(data.keys())
probabilities = list(data.values())
fig = plt.figure(figsize=(5,5))
plt.bar(titles,probabilities,color='green',width=0.4)
plt.title("turn: "+str(x+1))
canvas = FigureCanvasTkAgg(fig,frame)
canvas.get_tk_widget().grid(row=5,columnspan=10)
root.update()
def enter_start(event):
start()
root.bind('<Return>',enter_start)
entry = tk.Entry(frame)
button = tk.Button(frame,
text= "start",
fg='blue',
command= start)
heads = tk.Label(frame)
tails = tk.Label(frame)
button.grid(row=1,column=0)
entry.grid(row=1, column=1)
heads.grid(row=2,column=0,columnspan=4)
tails.grid(row=3,column=0,columnspan=4)
root.mainloop()