-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathoperator_precedence.py
More file actions
54 lines (42 loc) · 1.68 KB
/
Copy pathoperator_precedence.py
File metadata and controls
54 lines (42 loc) · 1.68 KB
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
class OperatorPrecedenceDemo:
def __init__(self, x, y):
self.x = x
self.y = y
def demonstrate_math_operations(self):
result = (self.x + self.y) * 2 ** 2 / 4
print("Math Operations Result:", result)
def demonstrate_bitwise_operations(self):
result_and = self.x & self.y
result_xor = self.x ^ self.y
result_or = self.x | self.y
print("Bitwise AND Result:", result_and)
print("Bitwise XOR Result:", result_xor)
print("Bitwise OR Result:", result_or)
def demonstrate_logical_operations(self):
result_not = not (self.x > self.y)
result_and = (self.x > 0) and (self.y < 10)
result_or = (self.x > 0) or (self.y < 10)
print("Logical NOT Result:", result_not)
print("Logical AND Result:", result_and)
print("Logical OR Result:", result_or)
def demonstrate_comparison_operations(self):
result_eq = self.x == self.y
result_gt = self.x > self.y
result_in = self.x in range(10)
print("Equality Result:", result_eq)
print("Greater Than Result:", result_gt)
print("Membership Test Result:", result_in)
def run_demonstrations(self):
print("Initial Values: x =", self.x, ", y =", self.y)
print("=" * 40)
self.demonstrate_math_operations()
print("=" * 40)
self.demonstrate_bitwise_operations()
print("=" * 40)
self.demonstrate_logical_operations()
print("=" * 40)
self.demonstrate_comparison_operations()
# Instantiate the OperatorPrecedenceDemo class
demo_instance = OperatorPrecedenceDemo(5, 3)
# Run the demonstrations
demo_instance.run_demonstrations()