Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BankingSystem:
- def __init__(self):
- # Initialize a dictionary to store account balance
- self.accounts = {}
- def create_account(self, timestamp, account_id):
- # Check if account already exists
- if account_id in self.accounts:
- return "false"
- else:
- # Create account with a balance of 0
- self.accounts[account_id] = 0
- return "true"
- def deposit(self, timestamp, account_id, amount):
- # Check if account exists
- if account_id not in self.accounts:
- return ""
- else:
- # Add amount to account balance
- self.accounts[account_id] += amount
- return str(self.accounts[account_id])
- def pay(self, timestamp, account_id, amount):
- # Check if account exists and has enough balance
- if account_id not in self.accounts or self.accounts[account_id] < amount:
- return ""
- else:
- # Subtract amount from account balance
- self.accounts[account_id] -= amount
- return str(self.accounts[account_id])
- def process_queries(self, queries):
- # Process each query and store the results
- results = []
- for query in queries:
- operation = query[0]
- if operation == "CREATE_ACCOUNT":
- result = self.create_account(query[1], query[2])
- elif operation == "DEPOSIT":
- result = self deposit(query[1], query[2], int(query[3]))
- elif operation == "PAY":
- result = self.pay(query[1], query[2], int(query[3]))
- results.append(result)
- return results
- # Example queries, this should be replaced with the actual input
- example_queries = [
- ["CREATE_ACCOUNT", "1", "account1"],
- ["CREATE_ACCOUNT", "2", "account1"],
- ["DEPOSIT", "3", "account1", "2700"],
- ["DEPOSIT", "4", "non-existing", "2700"],
- ["PAY", "5", "account1", "700"],
- ["PAY", "6", "non-existing", "2700"],
- ["PAY", "7", "account1", "2701"],
- ["PAY", "8", "account1", "2000"]
- ]
- # Create a banking
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement