Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Создайте класс, осуществляющий подсчет и изменение числа книг. Названия книг, их количество считываются одной строкой вида 'Boogeyman 66 Battleground 50', число книг - произвольное.
- В классе должен быть реализован конструктор, деструктор, методы просмотра числа, взятия и возвращения книг.
- Реализовать вывод начальных значений, взятие по 1 книге, возвращение по 1 книге с выводом текущего числа после вызова каждого из методов, меняющих значение книг.
- Типичный ответ одной строкой: 'Boogeyman 66 65 66 Battleground 50 49 50'.
- Пример входных данных:
- Boogeyman 66 Battleground 50
- Пример выходных данных:
- Boogeyman 66 65 66 Battleground 50 49 50
- Вариант
- """
- # class Books(object):
- # def __init__(self, list_books=input().split()):
- # self.name = []
- # self.count = []
- # self.full = []
- # for el in list_books:
- # self.full.append(el)
- # if el.isdigit():
- # self.count.append(int(el))
- # self.full.append([int(el)])
- # else:
- # self.name.append(el)
- # self.full.append([el])
- # # self.full_mut = list(self.full)
- # # my_dict = dict(zip(name, count))
- # # self.my_dict = my_dict
- # def __del__(self):
- # # self.print_books()
- # pass
- # def print_books(self):
- # # for k, v in self.my_dict.items():
- # # print(k, v, end=" ")
- # for el in self.full:
- # print(el, end=" ")
- # for el in self.full:
- # print(type(el), end=" ")
- # def get_books(self):
- # # for el in self.my_dict:
- # # self.my_dict[el] -= 1
- # # self.print_books()
- # for idx in range(len(self.full)):
- # try:
- # if self.full[idx].isdigit():
- # self.full.insert(idx + 1, int(self.full[idx]) - 1)
- # except:
- # pass
- # self.full.insert(len(self.full), int(self.full[-1]) - 1)
- # self.full_mut = list(self.full)
- # def return_books(self):
- # # for el in self.my_dict:
- # # self.my_dict[el] += 1
- # # self.print_books()
- # for idx in range(len(self.full_mut)):
- # try:
- # # if self.full[idx].isdigit():
- # if type(self.full[idx]) == int:
- # print("INT")
- # self.full.insert(idx + 1, int(self.full[idx]) + 1)
- # except:
- # pass
- # # self.full.insert(len(self.full), int(self.full[-1]) + 1)
- class Books(object):
- def __init__(self, list_books=input().split()):
- self.full = []
- for el in list_books:
- if el.isdigit():
- self.full.append([int(el)])
- else:
- self.full.append([el])
- def __del__(self):
- # self.print_books()
- pass
- def print_books(self):
- for el in self.full:
- if not type(el) == list:
- print(el, end=" ")
- else:
- for e in el:
- print(e, end=" ")
- def get_books(self):
- for idx in range(1, len(self.full) + 1, 2):
- self.full[idx].append(self.full[idx][0] - 1)
- def return_books(self):
- for idx in range(1, len(self.full) + 1, 2):
- self.full[idx].append(self.full[idx][1] + 1)
- a = Books()
- # a.print_books()
- a.get_books()
- # a.print_books()
- a.return_books()
- a.print_books()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement