So I made a code in oop where it would allow you to deposit money in a bank, and also withdraw it. I solved the part where I was able to deposit money but I'm not able to withdraw money from the bank. I would appreciate a fixed answer. Thanks!
class Bank:
def __init__(self,name,accountNumber,totalBalance):
self.name = name
self.accountNumber = {}
self.totalBalance = {}
def deposit(self):
print("What is your account number?")
x = input()
print("What balance are you depositing?")
y = input()
self.accountNumber[x] = y
print(self.accountNumber)
def withdraw(self):
print("What is your account number?")
s = int(input())
print("What balance are you withdrawing?")
f = int(input())
self.accountNumber[s] = self.accountNumber[s] - f
print(self.accountNumber)
Bank1 = Bank("MONEYYYYY",1234,53)
Bank1.deposit()
Bank1.withdraw()
If you know why it's not working then I would appreciate it if you could tell me why and fix it, thanks!
There are other problems with the design of your solution, but to address this particular one, you are subtracting the withdrawal amount from
self.accountNumber[s]instead of fromself.totalBalance. You are also setting the deposit amount in the same incorrect field.