← 返回 coinbase 的题目列表Bank System Class with Deposit, Withdraw, and Balance Check
类型:online_judge
coinbase
Design a bank system that supports the following operations:
Deposit: Add a certain amount of money to a specified account.
Withdraw: Withdraw a certain amount of money from a specified account. If the balance is insufficient, decline the operation.
Check Balance: Check the current balance of a specified account.
Please implement a class BankSystem to fulfill the above functionalities.
Input Description
Initialize account information when creating the bank system object, e.g., accounts = {'A': 1000, 'B': 2000}.
Methods include deposit(account_id, amount), withdraw(account_id, amount), and check_balance(account_id).
Test Cases
Initialization: accounts = {'A': 1000, 'B': 2000}
Deposit operation: deposit('A', 500), check_balance('A') should return 1500.
Withdraw operation: withdraw('B', 1000), check_balance('B') should return 1000.
Insufficient balance: withdraw('B', 1500), should return an error message or decline the operation.
Check balance: check_balance('A') should return 1500.
Example
Input
{'A': 1000, 'B': 2000}
deposit('A', 500)