-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoops.py
805 lines (605 loc) · 26.5 KB
/
oops.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
"""
Object Oriented Programming in Python
This file shows examples of object oriented programming in Python
using classes and objects. Dunders, decorators, and inheritance are
also utilized in the examples.
"""
"""
Basic Classes and Objects by creating a Person class using dunders and simple methods
"""
# Define a class named Person
class Person:
"""
Person class that has a constructor that takes two parameters for the name and age. The Person class has a method named say_hello that prints a greeting with the name of the person. The Person class has a method named say_age that prints the age of the person. The Person class has a method named say_hello_and_age that calls the say_hello and say_age methods. The Person class has a method named __str__ that returns a string representation of the person. The Person class has a method named __repr__ that returns a string representation of the person. The Person class has a method named __eq__ that returns True if the name and age are the same. The Person class has a method named __ne__ that returns True if the name or age are different. The Person class has a method named __lt__ that returns True if the age is less than another person's age. The Person class has a method named __le__ that returns True if the age is less than or equal to another person's age. The Person class has a method named __gt__ that returns True if the age is greater than another person's age. The Person class has a method named __ge__ that returns True if the age is greater than or equal to another person's age. The Person class has a method named __add__ that returns the sum of the ages of two people. The Person class has a method named __sub__ that returns the difference of the ages of two people. The Person class has a method named __mul__ that returns the product of the ages of two people. The Person class has a method named __truediv__ that returns the quotient of the ages of two people. The Person class has a method named __floordiv__ that returns the floor division of the ages of two people. The Person class has a method named __mod__ that returns the modulus of the ages of two people. The Person class has a method named __pow__ that returns the power of the ages of two people. The Person class has a method named __lshift__ that returns the left shift of the ages of two people. The Person class has a method named __rshift__ that returns the right shift of the ages of two people. The Person class has a method named __and__ that returns the bitwise and of the ages of two people.
"""
# Define the constructor
def __init__(self, name, age):
self.name = name
self.age = age
# Define a method named say_hello
def say_hello(self):
print(f"Hello, my name is {self.name}")
# Define a method named say_age
def say_age(self):
print(f"I am {self.age} years old")
# Define a method named say_hello_and_age
def say_hello_and_age(self):
self.say_hello()
self.say_age()
# Define a method named __str__
def __str__(self):
return f"Person(name={self.name}, age={self.age})"
# Define a method named __repr__
def __repr__(self):
return f"Person(name={self.name}, age={self.age})"
# Define a method named __eq__
def __eq__(self, other):
return self.name == other.name and self.age == other.age
# Define a method named __ne__
def __ne__(self, other):
return self.name != other.name or self.age != other.age
# Define a method named __lt__
def __lt__(self, other):
return self.age < other.age
# Define a method named __le__
def __le__(self, other):
return self.age <= other.age
# Define a method named __gt__
def __gt__(self, other):
return self.age > other.age
# Define a method named __ge__
def __ge__(self, other):
return self.age >= other.age
# Define a method named __add__
def __add__(self, other):
return self.age + other.age
# Define a method named __sub__
def __sub__(self, other):
return self.age - other.age
# Define a method named __mul__
def __mul__(self, other):
return self.age * other.age
# Define a method named __truediv__
def __truediv__(self, other):
return self.age / other.age
# Define a method named __floordiv__
def __floordiv__(self, other):
return self.age // other.age
# Define a method named __mod__
def __mod__(self, other):
return self.age % other.age
# Define a method named __pow__
def __pow__(self, other):
return self.age**other.age
# Define a method named __lshift__
def __lshift__(self, other):
return self.age << other.age
# Define a method named __rshift__
def __rshift__(self, other):
return self.age >> other.age
# Define a method named __and__
def __and__(self, other):
return self.age & other.age
# Show examples of using the Person class
person1 = Person("Alice", 30)
person2 = Person("Bob", 25)
person3 = Person("Charlie", 35)
print("person1:", person1)
print("person2:", person2)
print("person3:", person3)
print("person1 == person2:", person1 == person2)
print("person1 != person2:", person1 != person2)
print("person1 < person2:", person1 < person2)
print("person1 <= person2:", person1 <= person2)
print("person1 > person2:", person1 > person2)
print("person1 >= person2:", person1 >= person2)
print("person1 + person2:", person1 + person2)
print("person1 - person2:", person1 - person2)
print("person1 * person2:", person1 * person2)
print("person1 / person2:", person1 / person2)
print("person1 // person2:", person1 // person2)
print("person1 % person2:", person1 % person2)
print("person1 ** person2:", person1**person2)
print("person1 << person2:", person1 << person2)
print("person1 >> person2:", person1 >> person2)
print("person1 & person2:", person1 & person2, "\n")
"""
Inheritance of Classes
"""
# Define a class named Student that inherits from Person
class Student(Person):
"""
Student class that inherits from Person Class
Student class overrides the abstract methods area and perimeter and the Dunders __str__, __repr__, __eq__, __ne__, __lt__, __le__, __gt__, __ge__, __add__, __sub__, __mul__, __truediv__, __floordiv__, __mod__, and __pow__
The Student class has a constructor that takes three parameters for the name, age, and major. The Student class has a method named say_major that prints the major of the student. The Student class has a method named say_hello_and_major that calls the say_hello and say_major methods. The Student class has a method named __str__ that returns a string representation of the student. The Student class has a method named __repr__ that returns a string representation of the student. The Student class has a method named __eq__ that returns True if the name, age, and major are the same. The Student class has a method named __ne__ that returns True if the name, age, or major are different.
"""
# Define the constructor
def __init__(self, name, age, major):
super().__init__(name, age)
self.major = major
# Define a method named say_major
def say_major(self):
print(f"My major is {self.major}")
# Define a method named say_hello_and_major
def say_hello_and_major(self):
self.say_hello()
self.say_major()
# Define a method named __str__
def __str__(self):
return f"Student(name={self.name}, age={self.age}, major={self.major})"
# Define a method named __repr__
def __repr__(self):
return f"Student(name={self.name}, age={self.age}, major={self.major})"
# Define a method named __eq__
def __eq__(self, other):
return (
self.name == other.name
and self.age == other.age
and self.major == other.major
)
# Define a method named __ne__
def __ne__(self, other):
return (
self.name != other.name
or self.age != other.age
or self.major != other.major
)
# Show examples of using the Student class
student1 = Student("Alice", 20, "Computer Science")
student2 = Student("Bob", 22, "Mathematics")
student3 = Student("Charlie", 24, "Physics")
print("student1:", student1)
print("student2:", student2)
print("student3:", student3, "\n")
"""
Abstraction in Classes
"""
# Define an abstract base class named Shape
from abc import ABC, abstractmethod
class Shape(ABC):
"""
Shape Abstract Base Class that has abstract methods for area and perimeter.
The Shape class has methods for __str__, __repr__, __eq__, __ne__, __lt__, __le__, __gt__, __ge__, __add__, __sub__, __mul__, __truediv__, __floordiv__, __mod__, and __pow__
"""
# Define an abstract method named area
@abstractmethod
def area(self):
pass
# Define an abstract method named perimeter
@abstractmethod
def perimeter(self):
pass
# Define a method named __str__
def __str__(self):
return f"Shape(area={self.area()}, perimeter={self.perimeter()})"
# Define a method named __repr__
def __repr__(self):
return f"Shape(area={self.area()}, perimeter={self.perimeter()})"
# Define a method named __eq__
def __eq__(self, other):
return self.area() == other.area() and self.perimeter() == other.perimeter()
# Define a method named __ne__
def __ne__(self, other):
return self.area() != other.area() or self.perimeter() != other.perimeter()
# Define a method named __lt__
def __lt__(self, other):
return self.area() < other.area()
# Define a method named __le__
def __le__(self, other):
return self.area() <= other.area()
# Define a method named __gt__
def __gt__(self, other):
return self.area() > other.area()
# Define a method named __ge__
def __ge__(self, other):
return self.area() >= other.area()
# Define a method named __add__
def __add__(self, other):
return self.area() + other.area()
# Define a method named __sub__
def __sub__(self, other):
return self.area() - other.area()
# Define a method named __mul__
def __mul__(self, other):
return self.area() * other.area()
# Define a method named __truediv__
def __truediv__(self, other):
return self.area() / other.area()
# Define a method named __floordiv__
def __floordiv__(self, other):
return self.area() // other.area()
# Define a method named __mod__
def __mod__(self, other):
return self.area() % other.area()
# Define a method named __pow__
def __pow__(self, other):
return self.area() ** other.area()
# Define a class named Circle that inherits from Shape
class Circle(Shape):
"""
Circle class that inherits from Shape Abstract Base Class
Circle class overrides the abstract methods area and perimeter and the Dunders __str__, __repr__, __eq__, __ne__, __lt__, __le__, __gt__, __ge__, __add__, __sub__, __mul__, __truediv__, __floordiv__, __mod__, and __pow__
"""
# Define the constructor
def __init__(self, radius):
self.radius = radius
# Define a method named area
def area(self):
return 3.14159 * self.radius**2
# Define a method named perimeter
def perimeter(self):
return 2 * 3.14159 * self.radius
# Define a method named __str__
def __str__(self):
return f"Circle(radius={self.radius}, area={self.area()}, perimeter={self.perimeter()})"
# Define a method named __repr__
def __repr__(self):
return f"Circle(radius={self.radius}, area={self.area()}, perimeter={self.perimeter()})"
# Define a method named __eq__
def __eq__(self, other):
return self.radius == other.radius
# Define a method named __ne__
def __ne__(self, other):
return self.radius != other.radius
# Define a method named __lt__
def __lt__(self, other):
return self.radius < other.radius
# Define a method named __le__
def __le__(self, other):
return self.radius <= other.radius
# Define a method named __gt__
def __gt__(self, other):
return self.radius > other.radius
# Define a method named __ge__
def __ge__(self, other):
return self.radius >= other.radius
# Define a method named __add__
def __add__(self, other):
return self.radius + other.radius
# Define a method named __sub__
def __sub__(self, other):
return self.radius - other.radius
# Define a method named __mul__
def __mul__(self, other):
return self.radius * other.radius
# Define a method named __truediv__
def __truediv__(self, other):
return self.radius / other.radius
# Define a method named __floordiv__
def __floordiv__(self, other):
return self.radius // other.radius
# Define a method named __mod__
def __mod__(self, other):
return self.radius % other.radius
# Define a method named __pow__
def __pow__(self, other):
return self.radius**other.radius
# Show examples of using the Circle class
circle1 = Circle(5)
circle2 = Circle(10)
circle3 = Circle(15)
print("circle1:", circle1)
print("circle2:", circle2)
print("circle3:", circle3)
print("circle1 == circle2:", circle1 == circle2)
print("circle1 != circle2:", circle1 != circle2)
print("circle1 < circle2:", circle1 < circle2)
print("circle1 <= circle2:", circle1 <= circle2)
print("circle1 > circle2:", circle1 > circle2)
print("circle1 >= circle2:", circle1 >= circle2)
print("circle1 + circle2:", circle1 + circle2)
print("circle1 - circle2:", circle1 - circle2)
print("circle1 * circle2:", circle1 * circle2)
print("circle1 / circle2:", circle1 / circle2)
print("circle1 // circle2:", circle1 // circle2)
print("circle1 % circle2:", circle1 % circle2)
print("circle1 ** circle2:", circle1**circle2, "\n")
# Define a class named Rectangle that inherits from Shape
class Rectangle(Shape):
"""
Rectangle class that inherits from Shape Abstract Base Class
Rectangle class overrides the abstract methods area and perimeter and the Dunders __str__, __repr__, __eq__, __ne__, __lt__, __le__, __gt__, __ge__, __add__, __sub__, __mul__, __truediv__, __floordiv__, __mod__, and __pow__
"""
# Define the constructor
def __init__(self, width, height):
self.width = width
self.height = height
# Define a method named area
def area(self):
return self.width * self.height
# Define a method named perimeter
def perimeter(self):
return 2 * (self.width + self.height)
# Define a method named __str__
def __str__(self):
return f"Rectangle(width={self.width}, height={self.height}, area={self.area()}, perimeter={self.perimeter()})"
# Define a method named __repr__
def __repr__(self):
return f"Rectangle(width={self.width}, height={self.height}, area={self.area()}, perimeter={self.perimeter()})"
# Define a method named __eq__
def __eq__(self, other):
return self.width == other.width and self.height == other.height
# Define a method named __ne__
def __ne__(self, other):
return self.width != other.width or self.height != other.height
# Define a method named __lt__
def __lt__(self, other):
return self.area() < other.area()
# Define a method named __le__
def __le__(self, other):
return self.area() <= other.area()
# Define a method named __gt__
def __gt__(self, other):
return self.area() > other.area()
# Define a method named __ge__
def __ge__(self, other):
return self.area() >= other.area()
# Define a method named __add__
def __add__(self, other):
return self.area() + other.area()
# Define a method named __sub__
def __sub__(self, other):
return self.area() - other.area()
# Define a method named __mul__
def __mul__(self, other):
return self.area() * other.area()
# Define a method named __truediv__
def __truediv__(self, other):
return self.area() / other.area()
# Define a method named __floordiv__
def __floordiv__(self, other):
return self.area() // other.area()
# Define a method named __mod__
def __mod__(self, other):
return self.area() % other.area()
# Show examples of using the Rectangle class
rectangle1 = Rectangle(5, 10)
rectangle2 = Rectangle(10, 20)
rectangle3 = Rectangle(15, 30)
print("rectangle1:", rectangle1)
print("rectangle2:", rectangle2)
print("rectangle3:", rectangle3)
print("rectangle1 == rectangle2:", rectangle1 == rectangle2)
print("rectangle1 != rectangle2:", rectangle1 != rectangle2)
print("rectangle1 < rectangle2:", rectangle1 < rectangle2)
print("rectangle1 <= rectangle2:", rectangle1 <= rectangle2)
print("rectangle1 > rectangle2:", rectangle1 > rectangle2)
print("rectangle1 >= rectangle2:", rectangle1 >= rectangle2)
print("rectangle1 + rectangle2:", rectangle1 + rectangle2)
print("rectangle1 - rectangle2:", rectangle1 - rectangle2)
print("rectangle1 * rectangle2:", rectangle1 * rectangle2)
print("rectangle1 / rectangle2:", rectangle1 / rectangle2)
print("rectangle1 // rectangle2:", rectangle1 // rectangle2)
print("rectangle1 % rectangle2:", rectangle1 % rectangle2)
print("rectangle1 ** rectangle2:", rectangle1**rectangle2, "\n")
# Define a class named Square that inherits from Rectangle
class Square(Rectangle):
"""
Square class that inherits from Rectangle Class
Square class overrides the abstract methods area and perimeter and the Dunders __str__, __repr__, __eq__, __ne__, __lt__, __le__, __gt__, __ge__, __add__, __sub__, __mul__, __truediv__, __floordiv__, __mod__, and __pow__
The Square class has a constructor that takes a single parameter for the side length, and it calls the constructor of the Rectangle class with the side length as the width and height. Because the side length is the same for the width and height of a square. The area and perimeter methods are the same as the Rectangle class.
"""
# Define the constructor
def __init__(self, side):
super().__init__(side, side)
# Define a method named __str__
def __str__(self):
return f"Square(side={self.width}, area={self.area()}, perimeter={self.perimeter()})"
# Define a method named __repr__
def __repr__(self):
return f"Square(side={self.width}, area={self.area()}, perimeter={self.perimeter()})"
# Define a method named __eq__
def __eq__(self, other):
return self.width == other.width
# Define a method named __ne__
def __ne__(self, other):
return self.width != other.width
# Define a method named __lt__
def __lt__(self, other):
return self.area() < other.area()
# Define a method named __le__
def __le__(self, other):
return self.area() <= other.area()
# Define a method named __gt__
def __gt__(self, other):
return self.area() > other.area()
# Define a method named __ge__
def __ge__(self, other):
return self.area() >= other.area()
# Define a method named __add__
def __add__(self, other):
return self.area() + other.area()
# Define a method named __sub__
def __sub__(self, other):
return self.area() - other.area()
# Define a method named __mul__
def __mul__(self, other):
return self.area() * other.area()
# Define a method named __truediv__
def __truediv__(self, other):
return self.area() / other.area()
# Define a method named __floordiv__
def __floordiv__(self, other):
return self.area() // other.area()
# Define a method named __mod__
def __mod__(self, other):
return self.area() % other.area()
# Define a method named __pow__
def __pow__(self, other):
return self.area() ** other.area()
# Show examples of using the Square class
square1 = Square(5)
square2 = Square(10)
square3 = Square(15)
print("square1:", square1)
print("square2:", square2)
print("square3:", square3)
print("square1 == square2:", square1 == square2)
print("square1 != square2:", square1 != square2)
print("square1 < square2:", square1 < square2)
print("square1 <= square2:", square1 <= square2)
print("square1 > square2:", square1 > square2)
print("square1 >= square2:", square1 >= square2)
print("square1 + square2:", square1 + square2)
print("square1 - square2:", square1 - square2)
print("square1 * square2:", square1 * square2)
print("square1 / square2:", square1 / square2)
print("square1 // square2:", square1 // square2)
print("square1 % square2:", square1 % square2)
print("square1 ** square2:", square1**square2, "\n")
# Define a class named Triangle that inherits from Shape
class Triangle(Shape):
"""
Triangle class that inherits from Shape Abstract Base Class
Triangle class overrides the abstract methods area and perimeter and the Dunders __str__, __repr__, __eq__, __ne__, __lt__, __le__, __gt__, __ge__, __add__, __sub__, __mul__, __truediv__, __floordiv__, __mod__, and __pow__
The Triangle class has a constructor that takes four parameters for the base, height, and two sides. The area is calculated as 0.5 * base * height, and the perimeter is calculated as base + side1 + side2. The area and perimeter methods are the same as the Rectangle class.
"""
# Define the constructor
def __init__(self, base, height, side1, side2):
self.base = base
self.height = height
self.side1 = side1
self.side2 = side2
# Define a method named area
def area(self):
return 0.5 * self.base * self.height
# Define a method named perimeter
def perimeter(self):
return self.base + self.side1 + self.side2
# Define a method named __str__
def __str__(self):
return f"Triangle(base={self.base}, height={self.height}, side1={self.side1}, side2={self.side2}, area={self.area()}, perimeter={self.perimeter()})"
# Define a method named __repr__
def __repr__(self):
return f"Triangle(base={self.base}, height={self.height}, side1={self.side1}, side2={self.side2}, area={self.area()}, perimeter={self.perimeter()})"
# Define a method named __eq__
def __eq__(self, other):
return (
self.base == other.base
and self.height == other.height
and self.side1 == other.side1
and self.side2 == other.side2
)
# Define a method named __ne__
def __ne__(self, other):
return (
self.base != other.base
or self.height != other.height
or self.side1 != other.side1
or self.side2 != other.side2
)
# Define a method named __lt__
def __lt__(self, other):
return self.area() < other.area()
# Define a method named __le__
def __le__(self, other):
return self.area() <= other.area()
# Define a method named __gt__
def __gt__(self, other):
return self.area() > other.area()
# Define a method named __ge__
def __ge__(self, other):
return self.area() >= other.area()
# Define a method named __add__
def __add__(self, other):
return self.area() + other.area()
# Define a method named __sub__
def __sub__(self, other):
return self.area() - other.area()
# Define a method named __mul__
def __mul__(self, other):
return self.area() * other.area()
# Define a method named __truediv__
def __truediv__(self, other):
return self.area() / other.area()
# Define a method named __floordiv__
def __floordiv__(self, other):
return self.area() // other.area()
# Define a method named __mod__
def __mod__(self, other):
return self.area() % other.area()
# Define a method named __pow__
def __pow__(self, other):
return self.area() ** 2
# Show examples of using the Triangle class
triangle1 = Triangle(5, 10, 8, 8)
triangle2 = Triangle(10, 20, 16, 16)
triangle3 = Triangle(15, 30, 24, 24)
print("triangle1:", triangle1)
print("triangle2:", triangle2)
print("triangle3:", triangle3)
print("triangle1 == triangle2:", triangle1 == triangle2)
print("triangle1 != triangle2:", triangle1 != triangle2)
print("triangle1 < triangle2:", triangle1 < triangle2)
print("triangle1 <= triangle2:", triangle1 <= triangle2)
print("triangle1 > triangle2:", triangle1 > triangle2)
print("triangle1 >= triangle2:", triangle1 >= triangle2)
print("triangle1 + triangle2:", triangle1 + triangle2)
print("triangle1 - triangle2:", triangle1 - triangle2)
print("triangle1 * triangle2:", triangle1 * triangle2)
print("triangle1 / triangle2:", triangle1 / triangle2)
print("triangle1 // triangle2:", triangle1 // triangle2)
print("triangle1 % triangle2:", triangle1 % triangle2)
print("triangle1 ** triangle2:", triangle1**triangle2, "\n")
"""
Static Methods in Classes
"""
# Define a class that has static methods
class Math:
"""
Math class that has static methods for add, subtract, multiply, divide, power, modulus, floor_divide, left_shift, right_shift, and bitwise_and
"""
# Define a static method named add
@staticmethod
def add(x, y):
return x + y
# Define a static method named subtract
@staticmethod
def subtract(x, y):
return x - y
# Define a static method named multiply
@staticmethod
def multiply(x, y):
return x * y
# Define a static method named divide
@staticmethod
def divide(x, y):
return x / y
# Define a static method named power
@staticmethod
def power(x, y):
return x**y
# Define a static method named modulus
@staticmethod
def modulus(x, y):
return x % y
# Define a static method named floor_divide
@staticmethod
def floor_divide(x, y):
return x // y
# Define a static method named left_shift
@staticmethod
def left_shift(x, y):
return x << y
# Define a static method named right_shift
@staticmethod
def right_shift(x, y):
return x >> y
# Define a static method named bitwise_and
@staticmethod
def bitwise_and(x, y):
return x & y
# Show examples of using the static methods in the Math class
print("Math.add(10, 5):", Math.add(10, 5))
print("Math.subtract(10, 5):", Math.subtract(10, 5))
print("Math.multiply(10, 5):", Math.multiply(10, 5))
print("Math.divide(10, 5):", Math.divide(10, 5))
print("Math.power(10, 5):", Math.power(10, 5))
print("Math.modulus(10, 5):", Math.modulus(10, 5))
print("Math.floor_divide(10, 5):", Math.floor_divide(10, 5))
print("Math.left_shift(10, 5):", Math.left_shift(10, 5))
print("Math.right_shift(10, 5):", Math.right_shift(10, 5))
print("Math.bitwise_and(10, 5):", Math.bitwise_and(10, 5), "\n")
"""
Class Methods in Classes
"""