-
Code class UserInfo: def __init__(self, *args): self.first_name, self.last_name, self.age, self.job, self.hobbies = args def __getattr__(self, name): match name: case "full_name": return f'{self.first_name} {self.last_name}' case "email": return f'{self.first_name[0]}{self.last_name}@matrix.com'
Test Cases import codewars_test as test from solution import UserInfo .describe("Example") def test_group(): .it("test case") def test_case(): sample_user = UserInfo('agent', 'smith', 101, 'an Agent of the system', ['capture/kill neo', 'detroy zion','escape the matrix' ] ) test.assert_equals(sample_user.first_name, 'agent') test.assert_equals(sample_user.last_name, 'smith') test.assert_equals(sample_user.full_name, 'agent smith') test.assert_equals(sample_user.job, 'an Agent of the system') test.assert_equals(sample_user.hobbies, ['capture/kill neo', 'detroy zion','escape the matrix' ]) test.assert_equals(sample_user.email, 'asmith@matrix.com')
Output:
-
Code from dataclasses import dataclass, field@dataclass- class UserInfo:
first_name: strlast_name: strage: intjob: strhobbies: list@propertydef full_name(self):return f'{self.first_name} {self.last_name}'@propertydef email(self):return f'{self.first_name[0]}{self.last_name}@matrix.com'- def __init__(self, *args):
- self.first_name, self.last_name, self.age, self.job, self.hobbies = args
- def __getattr__(self, name):
- match name:
- case "full_name":
- return f'{self.first_name} {self.last_name}'
- case "email":
- return f'{self.first_name[0]}{self.last_name}@matrix.com'
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}