← 返回 capitalone 的题目列表Design a simple banking system
类型:online_judge
Design a simple banking system that supports the following functionalities:
Open Account: Each account has a unique account ID and an initial balance.
Deposit: Allows depositing a certain amount into the account.
Withdraw: Allows withdrawing a certain amount from the account, ensuring sufficient balance.
Check Balance: Allows checking the current balance of the account.
Provide interface functions and implementation. Provide sample test cases, for example an account with an initial balance of 100 should have 150 after a deposit of 50, and 80 after withdrawing 70. The data scale is no more than 1000 accounts.
class BankSystem:
def __init__(self):
pass
def open_account(self, initial_balance) -> int:
"""Create and return a new account ID.”"
pass
def deposit(self, account_id, amount) -> None:
pass
def withdraw(self, account_id, amount) -> bool:
"""Return whether the operation is successful.”"
pass
def get_balance(self, account_id) -> int:
pass
if __name__ == '__main__':
bank = BankSystem()
account = bank.open_account(100)
bank.deposit(account, 50)
bank.withdraw(account, 70)
print(bank.get_balance(account)) # Output should be 80
Example
Input
100 50 70