实现如下业务: 开户,存款100,查询余额,取款50,查询余额,取款200,查询余额
时间: 2023-06-19 12:02:46 浏览: 87
好的,以下是实现该业务的示例代码(使用 Python 语言):
```python
class BankAccount:
def __init__(self):
self.balance = 0
def open_account(self):
print("账户开户成功!")
def deposit(self, amount):
self.balance += amount
print(f"存入 {amount} 元,当前余额为 {self.balance} 元。")
def check_balance(self):
print(f"当前余额为 {self.balance} 元。")
def withdraw(self, amount):
if self.balance >= amount:
self.balance -= amount
print(f"取出 {amount} 元,当前余额为 {self.balance} 元。")
else:
print("余额不足,无法取款。")
# 创建银行账户
account = BankAccount()
# 开户
account.open_account()
# 存款100
account.deposit(100)
# 查询余额
account.check_balance()
# 取款50
account.withdraw(50)
# 查询余额
account.check_balance()
# 取款200
account.withdraw(200)
# 查询余额
account.check_balance()
```
输出结果如下:
```
账户开户成功!
存入 100 元,当前余额为 100 元。
当前余额为 100 元。
取出 50 元,当前余额为 50 元。
当前余额为 50 元。
余额不足,无法取款。
当前余额为 50 元。
```