-
Notifications
You must be signed in to change notification settings - Fork 0
/
task2.py
91 lines (61 loc) · 2.33 KB
/
task2.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
# Task2
# Calculator
# I made a calculator by python object-oriented programming which is based on classes and objects
# import abstract method to make a abstract class
from abc import ABCMeta, abstractmethod, ABC
# classes for basic mathematical operation
class Operation(metaclass=ABCMeta):
def input_operands(self):
self.operand_1 = int(input('Enter your First operand:'))
self.operand_2 = int(input('Enter your second operand:'))
@abstractmethod
def mathematical_operation(self):
pass
class Addition_operation(Operation):
def mathematical_operation(self):
self.input_operands()
print('\nRESULT:\nAddition:', self.operand_1 + self.operand_2)
print()
class Subtraction_operation(Operation, ABC):
def mathematical_operation(self):
self.input_operands()
print('\nRESULT:\nSubtraction:', self.operand_1 - self.operand_2)
print()
class Multiplication_operation(Operation):
def mathematical_operation(self):
self.input_operands()
print('\nRESULT:\nMultiplication:', self.operand_1 * self.operand_2)
print()
class Division_operation(Operation):
def mathematical_operation(self):
self.input_operands()
print('\nRESULT:\nDivision:', round((self.operand_1 / self.operand_2),4))
print()
# main interface
print('**** HELLO PYTHON CALCULATOR ****')
print()
try:
while True:
print("Here's your basic operation:")
print('PRESS[1] FOR ADDITION \nPRESS[2] FOR SUBTRACTION \nPRESS[3] FOR MULTIPLICATION \nPRESS[4] FOR DIVISION')
print('PRESS[5] FOR EXIT\n')
choice = int(input('Which operation do you want to perform:'))
if choice == 1:
a1 = Addition_operation()
a1.mathematical_operation()
elif choice == 2:
s1 = Subtraction_operation()
s1.mathematical_operation()
elif choice == 3:
m1 = Multiplication_operation()
m1.mathematical_operation()
elif choice == 4:
d1 = Division_operation()
d1.mathematical_operation()
elif choice == 5:
print("Thankyou for using.\nGoodbye!")
exit()
else:
print('Invalid Choice!!\nPLS choose a given numbers')
except ValueError:
print("Invalid Input!! Enter an integer")