-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculator.py
58 lines (47 loc) · 1.66 KB
/
Calculator.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
from math import sqrt
# Useful datatype for two inputs from the user
class dualInputs:
def __init__(self) -> None:
self.inputOne = input("Parameter one: ")
self.inputTwo = input("Parameter two: ")
# Function to reduce reused code
def addSub(modifier):
usrInput = dualInputs()
result = int(usrInput.inputOne) + (int(usrInput.inputTwo) * modifier)
print(f"The result is: {result}")
# Intro sequence
print(""""Welcome to the god awful calculator!
All operations are availible under \"help\"""")
# Primary execution process
while True:
# Baseline command
usrCommand = input("-> ")
# Switch statement to choose operation mode
match usrCommand.lower():
#Handle Addition situation
case "add":
addSub(1)
# Subtraction
case "subtract":
addSub(-1)
# Multiplication
case "multiply":
usrInput = dualInputs()
result = int(usrInput.inputOne) * int(usrInput.inputTwo)
print(f"The result is: {result}")
case "divide":
usrInput = dualInputs()
result = int(usrInput.inputOne) / int(usrInput.inputTwo)
print(f"The result is: {result}")
# Exponential
case "exponential":
usrInput = dualInputs()
result = int(usrInput.inputOne) ** int(usrInput.inputTwo)
print(f"The result is: {result}")
# Square Root
case "square root":
usrInput = input("Parameter to square root: ")
result = sqrt(int(usrInput))
print(f"The result is: {result}")
# Command to exit the program
case "exit": break