Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.90 KB | None | 0 0
  1. """
  2. Создайте класс, осуществляющий подсчет и изменение числа книг. Названия книг, их количество считываются одной строкой вида 'Boogeyman 66 Battleground 50', число книг - произвольное.
  3. В классе должен быть реализован конструктор, деструктор, методы просмотра числа, взятия и возвращения книг.
  4. Реализовать вывод начальных значений, взятие по 1 книге, возвращение по 1 книге с выводом текущего числа после вызова каждого из методов, меняющих значение книг.
  5. Типичный ответ одной строкой: 'Boogeyman 66 65 66 Battleground 50 49 50'.
  6.  
  7. Пример входных данных:
  8. Boogeyman 66 Battleground 50
  9.  
  10. Пример выходных данных:
  11. Boogeyman 66 65 66 Battleground 50 49 50
  12. Вариант
  13. """
  14.  
  15.  
  16. # class Books(object):
  17.  
  18. #     def __init__(self, list_books=input().split()):
  19. #         self.name = []
  20. #         self.count = []
  21. #         self.full = []
  22. #         for el in list_books:
  23. #             self.full.append(el)
  24.  
  25. #             if el.isdigit():
  26. #                 self.count.append(int(el))
  27. #                 self.full.append([int(el)])
  28. #             else:
  29. #                 self.name.append(el)
  30. #                 self.full.append([el])
  31. #         # self.full_mut = list(self.full)
  32. #         # my_dict = dict(zip(name, count))
  33. #         # self.my_dict = my_dict
  34.  
  35. #     def __del__(self):
  36. #         # self.print_books()
  37. #         pass
  38.  
  39. #     def print_books(self):
  40. #         # for k, v in self.my_dict.items():
  41. #         #     print(k, v, end=" ")
  42. #         for el in self.full:
  43. #             print(el, end=" ")
  44. #         for el in self.full:
  45. #             print(type(el), end=" ")
  46.  
  47. #     def get_books(self):
  48. #         # for el in self.my_dict:
  49. #         #     self.my_dict[el] -= 1
  50. #         # self.print_books()
  51. #         for idx in range(len(self.full)):
  52. #             try:
  53. #                 if self.full[idx].isdigit():
  54. #                     self.full.insert(idx + 1, int(self.full[idx]) - 1)
  55. #             except:
  56. #                 pass
  57. #         self.full.insert(len(self.full), int(self.full[-1]) - 1)
  58. #         self.full_mut = list(self.full)
  59.  
  60. #     def return_books(self):
  61. #         # for el in self.my_dict:
  62. #         #     self.my_dict[el] += 1
  63. #         #     self.print_books()
  64.  
  65. #         for idx in range(len(self.full_mut)):
  66. #             try:
  67. #                 # if self.full[idx].isdigit():
  68. #                 if type(self.full[idx]) == int:
  69. #                     print("INT")
  70. #                     self.full.insert(idx + 1, int(self.full[idx]) + 1)
  71. #             except:
  72. #                 pass
  73. #         # self.full.insert(len(self.full), int(self.full[-1]) + 1)
  74.  
  75.  
  76. class Books(object):
  77.  
  78.     def __init__(self, list_books=input().split()):
  79.         self.full = []
  80.         for el in list_books:
  81.  
  82.             if el.isdigit():
  83.                 self.full.append([int(el)])
  84.             else:
  85.                 self.full.append([el])
  86.  
  87.     def __del__(self):
  88.         # self.print_books()
  89.         pass
  90.  
  91.     def print_books(self):
  92.         for el in self.full:
  93.             if not type(el) == list:
  94.                 print(el, end=" ")
  95.             else:
  96.                 for e in el:
  97.                     print(e, end=" ")
  98.  
  99.     def get_books(self):
  100.         for idx in range(1, len(self.full) + 1, 2):
  101.             self.full[idx].append(self.full[idx][0] - 1)
  102.  
  103.     def return_books(self):
  104.         for idx in range(1, len(self.full) + 1, 2):
  105.             self.full[idx].append(self.full[idx][1] + 1)
  106.  
  107.  
  108. a = Books()
  109. # a.print_books()
  110. a.get_books()
  111. # a.print_books()
  112. a.return_books()
  113. a.print_books()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement