-
Notifications
You must be signed in to change notification settings - Fork 0
Level 2 #2
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
base: main
Are you sure you want to change the base?
Level 2 #2
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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| venv/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,14 +5,23 @@ | |
| 1. Создайте класс User и перенесите всю логику работы с пользователем туда. | ||
| """ | ||
|
|
||
| class User: | ||
| def __init__(self, username: str, user_id: int, name: str): | ||
| self.username = username | ||
| self.user_id = user_id | ||
| self.name = name | ||
|
|
||
| def make_username_capitalized(username: str): | ||
| return username.capitalize() | ||
|
|
||
| def make_username_capitalized(self): | ||
|
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. 👍 в целом верно |
||
| return self.username.capitalize() | ||
|
|
||
| def generate_short_user_description(username: str, user_id: int, name: str): | ||
| return f'User with id {user_id} has {username} username and {name} name' | ||
|
|
||
| def generate_short_user_description(self): | ||
|
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. 👍 тоже верно все - спрятали в класс, убрали атрибуты - используем поля класса |
||
| return f'User with id {self.user_id} has {self.username} username and {self.name} name' | ||
|
|
||
| class User: | ||
| pass # код писать тут | ||
|
|
||
| if __name__ == '__main__': | ||
| user = User(username='login', user_id=1, name='first_name') | ||
|
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. 👍 |
||
| user.username = user.make_username_capitalized() | ||
| description = user.generate_short_user_description() | ||
| print(description) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,4 +11,42 @@ | |
|
|
||
|
|
||
| class User: | ||
| pass # код писать тут | ||
| def __init__(self, first_name: str, last_name: str, age: int): | ||
| self.first_name = first_name | ||
| self.last_name = last_name | ||
| self.age = age | ||
|
|
||
| def should_be_banned(self) -> bool: | ||
| return self.last_name in SURNAMES_TO_BAN | ||
|
|
||
| if __name__ == '__main__': | ||
| user_1 = User(first_name='Jay', last_name='Vaughn', age=22) | ||
| user_2 = User(first_name='Bob', last_name='Wilhelm', age=30) | ||
| user_3 = User(first_name='Steave', last_name='Cubin',age=29) | ||
| user_4 = User(first_name='Alex', last_name='Santaros', age=25) | ||
|
|
||
| if user_1.should_be_banned(): | ||
|
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. 💡 чтобы каждый раз не писать одну и ту же логику - сделай функцию вне класса def check_user(user):
if ... print else ... printне забудь про аннотации типов |
||
| print(f'{user_1.first_name} {user_1.last_name} should be banned') | ||
|
|
||
| else: | ||
| print(f'{user_1.first_name} {user_1.last_name} is allowed') | ||
|
|
||
| if user_2.should_be_banned(): | ||
| print(f'{user_2.first_name} {user_2.last_name} should be banned') | ||
|
|
||
| else: | ||
| print(f'{user_2.first_name} {user_2.last_name} is allowed') | ||
|
|
||
| if user_3.should_be_banned(): | ||
| print(f'{user_3.first_name} {user_3.last_name} should be banned') | ||
|
|
||
| else: | ||
| print(f'{user_3.first_name} {user_3.last_name} is allowed') | ||
|
|
||
| if user_4.should_be_banned(): | ||
| print(f'{user_4.first_name} {user_4.last_name} should be banned') | ||
|
|
||
| else: | ||
| print(f'{user_4.first_name} {user_4.last_name} is allowed') | ||
|
|
||
|
|
||
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.
💡 укажи аннотацию иниту на выход тоже