-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator_basic.py
85 lines (71 loc) · 1.73 KB
/
calculator_basic.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
# calculator with all buttons
import simpleguitk
# intialize globals
x=float(raw_input("set store")) ##
y=float(raw_input("set operand")) ##
store = x
operand = y
# event handlers for calculator with a store and operand
def output():
"""prints contents of store and operand"""
print "Store = ", store
print "Operand = ", operand
print ""
def swap():
""" swap contents of store and operand"""
global store, operand
store, operand = operand, store
output()
def add():
""" add operand to store"""
global store
store = store + operand
output()
def sub():
""" subtract operand from store"""
global store
store = store - operand
output()
def mult():
""" multiply store by operand"""
global store
store = store * operand
output()
def div():
""" divide store by operand"""
global store
store = store / operand
output()
def exp():
""" exponate store by operand """
global store
store = store ** operand
output()
def root():
""" root store by operand """
global store
store= store ** (1.0/operand)
output()
def new_var():
""" sets new store and operand """
x=float(raw_input("set store")) ##
y=float(raw_input("set operand")) ##
global store
store= x
global operand
operand = y
output()
# create frame
f = simpleguitk.create_frame("Calculator",300,300)
# register event handlers
f.add_button("Print", output, 100)
f.add_button("Swap", swap, 100)
f.add_button("Add", add, 100)
f.add_button("Sub", sub, 100)
f.add_button("Mult", mult, 100)
f.add_button("Div", div, 100)
f.add_button("Exp", exp, 100)
f.add_button("Root",root,100)
f.add_button("NEW VARIABLES", new_var, 200)
# get frame rolling
f.start()