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

Update IBank_part1_2.py #3591

Open
wants to merge 3 commits 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
39 changes: 20 additions & 19 deletions Module8/practice/IBank/IBank_part1_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,60 @@ def __init__(self, name: str, passport: str, phone_number: str, start_balance: i
self.name = name
self.passport = passport
self.phone_number = phone_number
# self.balance = start_balance
self.__balance = start_balance # TODO: Закрываем прямой доступ к балансу
self.__balance = start_balance

def full_info(self) -> str:
"""
Полная информация о счете в формате: "Иван баланс: 100 руб. паспорт: 3200 123456 т.+7-900-200-02-03"
"""
return f"..."
return f"{self.name} баланс: {self.balance} руб. паспорт: {self.passport} т.{self.phone_number}"

def __repr__(self) -> str:
"""
:return: Информацию о счете в виде строки в формате "Иван баланс: 100 руб."
"""
return f"..."
return f"{self.name} баланс: {self.balance} руб."

# TODO: реализуйте getter для просмотра баланса
# Подробнее тут: https://pythobyte.com/using-getters-and-setters-in-python-5205-840ed13f/
@property
def balance(self) -> int:
return ...
return self.__balance

def deposit(self, amount: int) -> None:
"""
Внесение суммы на текущий счет
:param amount: сумма
"""
pass
self.__balance += amount

def withdraw(self, amount: int) -> None:
"""
Снятие суммы с текущего счета
:param amount: сумма
"""
pass
if self.__balance - amount < 0:
raise ValueError
self.__balance -= amount


# Создаем тестовый аккаунт:
account1 = Account("Алексей", "3232 456124", "+7-901-744-22-99", start_balance=500)

# Вносим сумму на счет:
# account1.deposit(600)
# print(account1)
account1.deposit(600)
print(account1)

# Снимаем деньги со счета:
# try:
# account1.withdraw(1000)
# except ValueError as e:
# print(e)
# print(account1)
try:
account1.withdraw(1000)
except ValueError as e:
print(e)
print(account1)

# Пробуем снять еще:
# try:
# account1.withdraw(1000)
# except ValueError as e:
# print(e)
# print(account1)
try:
account1.withdraw(1000)
except ValueError as e:
print(e)
print(account1)