Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add update #1656

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,45 @@
class Person:
# write your code here
pass
people = {}

def __init__(self, name: str, age: int) -> None:
if name in Person.people:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check for an existing person with the same name is correct, but it only prints an error message. Consider raising an exception or handling this case more robustly if needed.

print(f"Error: A person with the name \"{name}\" already exists.")
else:
self.name = name
self.age = age
Person.people[name] = self


def create_person_list(people: list) -> list:
# write your code here
pass
persons = []

for person_data in people:
name = person_data["name"]
age = person_data["age"]
if name not in Person.people:
person = Person(name, age)
persons.append(person)
else:
persons.append(Person.people[name]) # Використати вже створеного

# Додавання атрибутів wife та husband
for person_data in people:
person = Person.people[person_data["name"]]

# Перевірка існування дружини
if "wife" in person_data and person_data["wife"]:
wife_name = person_data["wife"]
if wife_name in Person.people:
person.wife = Person.people[wife_name]
else:
print(f"Warning: Wife with name \"{wife_name}\" don't exist")
Comment on lines +30 to +35

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning message for a non-existent wife is informative, but consider whether additional handling is needed if the wife is not found.


# Перевірка існування чоловіка
if "husband" in person_data and person_data["husband"]:
husband_name = person_data["husband"]
if husband_name in Person.people:
person.husband = Person.people[husband_name]
else:
print(f"Husband with name \"{husband_name}\" don't exist")
Comment on lines +38 to +43

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the wife check, the warning message for a non-existent husband is informative, but consider whether additional handling is needed if the husband is not found.


return persons
Loading