-
Notifications
You must be signed in to change notification settings - Fork 2
/
lwdcalculator.py
57 lines (46 loc) · 1.61 KB
/
lwdcalculator.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
class Calculator:
user_response : str
result : float
def __init__(self):
self.result = 0
def get_input(self):
''' get input and stores in user_response '''
self.user_response = input("Please enter two numbers : ")
def calculate_default(self) -> float:
'''legacy code'''
values = self.user_response
while isinstance(values, str):
try:
values = [int(i) for i in values.split()]
except ValueError:
values = input("Input should contain numbers only, please try again : ")
print("""
1. Add
2. Subtract
3. Multiply
4. Divide
""")
operation = input("Please choose an operation : ")
while isinstance(operation, str):
try:
operation = int(operation)
except ValueError:
operation = input("Input should contain numbers only, please try again : ")
# can be simplified with dictionary
if operation == 1:
result = values[0] + values[1]
print(result)
else:
print("No valid operation chosen.")
def calculate_guy(self) -> float:
'''process user_response string and returns calculated result'''
pass
def calculate_tuti(self) -> float:
'''process user_response string and returns calculated result'''
pass
def calculate_bw(self) -> float:
'''process user_response string and returns calculated result'''
pass
def get_result(self):
'''output'''
print(f"Result is {self.result}.")