Advertisement
Razorspined

Untitled

Jan 14th, 2025
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. class A:
  2.    
  3.     def __init__(self, a):
  4.         self.chislo = a
  5.        
  6.     def __eq__(self, other):
  7.         return self.chislo == other.chislo
  8.    
  9.     def __str__(self):
  10.         return f'chisloto e {self.chislo}'
  11.  
  12. class B:
  13.    
  14.     def __init__(self):
  15.         self.obekti = []
  16.    
  17.     def find(self, obj):
  18.         found = False
  19.         for x in self.obekti:
  20.             if x.chislo == obj:
  21.                 found = True
  22.         return found
  23.        
  24.     def kotka (self, obj):
  25.         self.obekti.append(obj)
  26.        
  27.     def __add__(self, obj):
  28.         self.obekti.append(obj)
  29.         return self
  30.    
  31.     def __str__(self):
  32.         temp = ""
  33.         for x in self.obekti:
  34.             temp += str(x) + "\n"
  35.         return temp
  36.  
  37.  
  38. a = A(12)
  39. b = A(23)
  40. c = B()
  41. c.kotka(a)
  42. c = c + b
  43.  
  44. print(a)
  45.  
  46. print(c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement