Advertisement
kompilainenn

Untitled

Mar 20th, 2023
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. class FloatValue:
  2.     def __set_name__(self, cls, name):
  3.         self.name = "_" + name
  4.    
  5.     def __get__(self, obj, cls):
  6.         return getattr(obj, self.name)
  7.  
  8.     def __set__(self, obj, val):
  9.         if type(val) != float:
  10.             raise TypeError("Присваивать можно только вещественный тип данных.")
  11.         setattr(obj, self.name, val)
  12.    
  13. class Cell:
  14.    
  15.     value = FloatValue()
  16.    
  17.     def __init__(self, value = 0.0):
  18.         self.value = value
  19.        
  20. class TableSheet:
  21.     def __init__ (self, N, M):
  22.         self.cells = []
  23.         for i in range(N):
  24.             self.temp = []
  25.             for j in range(M):
  26.                 self.temp.append(Cell())
  27.             self.cells.append(self.temp)
  28.  
  29. table = TableSheet(5, 3)
  30. counter = 1.0
  31.  
  32. for item in table.cells:
  33.     for cell in item:
  34.         cell = Cell(counter)
  35.         counter += 1.0
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement