87/100 Polymorphism and Magic Methods - Exercise 02. Groups Python
Здравейте, имам следното затруднение. Кода ми работи почти перфектно с изключение на едно нещо. Вместо да принтира:
3
Group Special with members Elon Musk,
Warren Musk
Person 0: Aliko Dangote
Person 0: Aliko Dangote
Person 1: Bill Gates
Person 2: Warren Buffet
Person 3: Elon Musk
Person 4: Warren Musk
То принитра:
3
Group Special with members Elon Musk, Warren Musk
Aliko Dangote
Aliko Dangote
Bill Gates
Warren Buffet
Elon Musk
Warren Musk
Ето линк към задачата:
https://judge.softuni.bg/Contests/Practice/Index/1943#1
Това е моят код:
class Person:
persons_list = []
person_num = 0
def __init__(self, name, surname):
self.name = name
self.surname = surname
def __repr__(self):
return self.name + " " + self.surname
def __add__(self, other):
return self.name + " " + other.surname
class Group:
def __init__(self, name, people: list):
self.name = name
self.people = people
def __add__(self, other):
return self.people + other.people
def __len__(self):
return len(self.people)
def __repr__(self):
persons = ', '.join([str(x) for x in self.people])
return f"Group {self.name} with members {persons}"
Бих се радвал много на отговор, благодаря Ви!