-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
base: master
Are you sure you want to change the base?
add update #1656
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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: | ||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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.