Using Python- Develop a class BankAccount that supports these methods: • __init_
ID: 3763479 • Letter: U
Question
Using Python- Develop a class BankAccount that supports these methods:
• __init__(): Initializes the bank account balance to the value of the input argument, or to 0 if no input argument is given
• withdraw(): Takes an amount as input and withdraws it from the balance
• deposit(): Takes an amount as input and adds it to the balance
• balance(): Returns the balance on the account
>>> x = BankAccount(700)
>>> x.balance())
700.00
>>> x.withdraw(70)
>>> x.balance()
630.00
>>> x.deposit(7)
>>> x.balance()
637.00
Explanation / Answer
class BankAccount:
def __init__(self):
self.balance = 0
def __init__(self,int amount):
self.balance = amount
def balance(self):
return self.balance
def withdraw(self, amount):
if amount < self.balance :
self.balance -= amount
return self.balance
def deposit(self, amount):
self.balance += amount
return self.balance
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.