forked from JeanRusli/eecs448lab9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.py
55 lines (46 loc) · 1.62 KB
/
controller.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
import model
import view
class controller:
def __init__(self):
self.m = model.Model()
self.v = view.View()
def program(self):
self.v.welcomeMessage()
while 1:
Exit = False
while Exit == False: #Loops until valid 1st number input
num1 = self.v.inputNumber("1st")
Exit = self.m.validateNumber(num1)
if Exit == False: #If input number is not valid
self.v.invalidNumber()
continue
else:
num1 = self.m.returnTrueValue(num1) #This changes the number to the previous solution if 'ans' was entered
Exit = False
while Exit == False: #Loops until valid operator input
op = self.v.inputOperator()
Exit = self.m.validateOperator(op)
if Exit == False: #If input operator is not valid
self.v.invalidOperator()
continue
Exit = False
while Exit == False: #Loops until valid 2nd number input
num2 = self.v.inputNumber("2nd")
Exit = self.m.validateNumber(num2)
if Exit == False: #If input number is not valid
self.v.invalidNumber()
continue
else:
num2 = self.m.returnTrueValue(num2) #This changes the number to the previous solution if 'ans' was entered
if self.m.divByZero(num2, op) == True: #Checks for divide by zero error
self.v.outputError("Error! Divide By Zero!")
Exit = False
continue
result = self.m.performOperation(num1, num2, op)
self.v.printSolution(result[0], result[1], result[2], result[3])
goAgain = self.v.userContinue()
if goAgain != "Y" and goAgain != "y" and goAgain != "Yes" and goAgain != "yes": #If user wants to exit
break
self.v.endMessage()
c = controller()
c.program()