Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
venv/

Choose a reason for hiding this comment

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

💡 вообщем то сильно без разницы, я чтобы окружение под ногами не мешалось обычно в .venv делаю (как и многие тулзы вроде poetry, pdm) и прочих

3 changes: 2 additions & 1 deletion level_1/a_user_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ def __init__(self, name: str, username: str, age: int, phone: str):


if __name__ == '__main__':
pass # код писать тут
new_user = User(name="Human", username="Towel", age=22, phone="+7(999)999-99-99")

Choose a reason for hiding this comment

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

👍

print(f"Информация о пользователе:\nИмя - {new_user.name}.\nЛогин - {new_user.username}.\nВозраст - {new_user.age}.\nМобильный телефон - {new_user.phone}.")

Choose a reason for hiding this comment

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

💡 еще можно сделать метод __str__(self) -> str в User и его использовать тут


5 changes: 3 additions & 2 deletions level_1/b_student_full_name_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ def get_full_name(self):


if __name__ == '__main__':
pass # код писать тут

student = Student(name='Mark', surname='Proskurin', faculty='Python Development', course=2)

Choose a reason for hiding this comment

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

👍

get_full_student_name = student.get_full_name()
print(get_full_student_name)
9 changes: 7 additions & 2 deletions level_1/c_product_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@


class Product:
pass # код писать тут
def __init__(self, name: str, description: str, price: int, weight: int):

Choose a reason for hiding this comment

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

👍 в целом все верно
💡 у конструктора тоже указывай аннотацию на возвращаемое значение -> None
💡 для price лучше использовать Decimal

self.name = name
self.description = description
self.price = price
self.weight = weight


if __name__ == '__main__':
pass # код писать тут
product = Product(name='Chair', description='Very comfortable office chair', price='300$', weight=22)

Choose a reason for hiding this comment

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

🔴 price у нас в аннотации указан как int, а передается строка

print(f"Information about product:\nName - {product.name}.\nDescription - {product.description}.\nPrice - {product.price}.\nWeight - {product.weight} lb. ")
8 changes: 5 additions & 3 deletions level_1/d_bank_account_increase_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ def __init__(self, owner_full_name: str, balance: float):
self.balance = balance

def increase_balance(self, income: float):
pass # код писать тут

self.balance += income

Choose a reason for hiding this comment

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

💡 задай аннотацию на возвращаемое значение, используй -> None, если ничего не возвращает


if __name__ == '__main__':
pass # код писать тут
bank_account = BankAccount(owner_full_name='User Name', balance=1200.91)

Choose a reason for hiding this comment

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

👍 все верно
💡 бонусом попробуй сделать баланс 0.2 и увеличить его потом 0.1 и проанализируй результат

print(f'Баланс счёта: {bank_account.balance}')
bank_account.increase_balance(259.22)
print(f'Ваш баланс после пополнения: {bank_account.balance}')
23 changes: 21 additions & 2 deletions level_1/e_bank_account_decrease_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,27 @@


class BankAccount:
pass # код писать тут
def __init__(self, owner_full_name: str, balance: float):
self.owner_full_name = owner_full_name
self.balance = balance

def increase_balance(self, income: float):
self.balance += income

def decrease_balance(self, expense: float):

Choose a reason for hiding this comment

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

💡 указывай аннотации типов на выходное значение, иначе непонятно, либо функция ниче не возращает, либо забыли указать аннотацию

if self.balance - expense < 0:

Choose a reason for hiding this comment

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

👍 абсолютно верно, не трогаем баланс, пока не уверены что можем с него списать заданную сумму

raise ValueError('На вашем счёте недостаточно средств')
self.balance -= expense


if __name__ == '__main__':
pass # код писать тут
account = BankAccount('Name User', 1000.0)

Choose a reason for hiding this comment

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

👍 все верно

account.decrease_balance(500)
print(f'Баланс после снятия средств: {account.balance}')

try:
account.decrease_balance(2000)
except ValueError as e:
print(f'Ошибка: {e}')

print(f'Баланс после неудачной попытки снятия средств: {account.balance}')