forked from ZCW-Data1dot2/scicalc-team-cocoa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-app.py
146 lines (135 loc) · 4.47 KB
/
main-app.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#import matplotlib.pyplot as plt
from calculator import Calculator
from getValue import Value
display_modes = ['decimal', 'binary', 'octal', 'hexadecimal']
val_in_mem = 0
def calcMenu():
print("""
TEAM COCOA CALCULATOR PROGRAM
TODAYS SPECIALS:
1) ADD
2) SUBTRACT
3) MULTIPLY
4) DIVIDE
5) SQUARE
6) SQUARE ROOT
7) EXPONENTS
8) EXIT
""")
choice = int(input("PLEASE ENTER A NUMBER BETWEEN 1 - 8: \n"))
return choice
def display(int_answer, disp_mode):
if disp_mode == 'binary':
return bin(int_answer)
elif disp_mode == 'hexadecimal':
return hex(int_answer)
elif disp_mode == 'octal':
return oct(int_answer)
elif disp_mode == 'decimal':
return float(int_answer)
else:
return float(int_answer)
def switchDisplayMode(user_choice, prev_mode):
global display_modes
if user_choice == 'default':
disp_mode = display_modes[prev_mode]
else:
disp_mode = user_choice
return disp_mode
def displayResult(x: float):
print(f"Output: {x}", "\n")
def performCalcLoop(calc):
global val_in_mem
value = Value()
disp_prev_num = 0
disp_ask = input("Set a display mode? y or n\n")
if disp_ask == '' or disp_ask == 'n':
disp_inpt = 'default'
elif disp_ask == 'y':
disp_inpt = input("Which mode\n" + str(display_modes) + '\n')
choice = "" #Set choice to a value so it can meet the condition below and start the loop
while choice != 8:
if disp_prev_num > 3:
disp_prev_num = 0
disp_mode = switchDisplayMode(disp_inpt, disp_prev_num)
choice = calcMenu()
if choice == 1:
print("Add")
a, b = value.getAddNum()
result = calc.add(a, b)
dResult = display(result, disp_inpt)
displayResult(dResult)
elif choice == 2:
print("Subtract")
a, b = value.getSubNum()
result = calc.sub(a, b)
dResult = display(result, disp_inpt)
displayResult(dResult)
elif choice == 3:
print("Multiply")
a, b = value.getMultiNum()
result = calc.mul(a, b)
dResult = display(result, disp_inpt)
displayResult(dResult)
elif choice == 4:
print("Divide")
a, b = value.getDivNum()
dResult = display(result, disp_inpt)
displayResult(dResult)
elif choice == 5:
print("Square")
a = value.getSquared()
result = calc.squ(a)
dResult = display(result, disp_inpt)
displayResult(dResult)
elif choice == 6:
print("Square Root")
a = value.getRoot()
result = calc.roo(a)
dResult = display(result, disp_inpt)
displayResult(dResult)
elif choice == 7:
print("Exponent")
a, b = value.getExponent()
result = calc.exp(a, b)
displayResult(result)
elif choice == 8:
print("Calculator is now OFF")
#sys.exit(0)
# elif choice == 8:
# print("Lets make a pie chart!")
# subcount = int(input("How many subjects are on your pie chart?\n"))
# for x in range(0, subcount):
# sub = str(input("Please enter your subject\n"))
# subject_list.append(sub)
#
# # percentage = input(input("How much of each on your pie?\n"))
# for x in range(0, subcount):
# percent = input("Please enter the percentage for each subject\n")
# percent_list.append(percent)
# print("Please wait....creating pie")
# pie(subject_list, percent_list)
else:
print("Invalid choice: Please enter a number between 1 - 8\n")
disp_prev_num += 1
user_inpt = input()
if user_inpt == 'm+':
if disp_mode == 'octal':
val_in_mem = int(result,8)
elif disp_mode == 'binary':
val_in_mem = int(result,2)
elif disp_mode == 'hexadecimal':
val_in_mem = int(result,16)
elif disp_mode == 'decimal':
val_in_mem = result
print(val_in_mem)
if user_inpt == 'mc':
val_in_mem = 0
# main start
def main():
calc = Calculator()
value = Value()
performCalcLoop(calc)
print("Done Calculating.")
if __name__ == '__main__':
main()