classes
This commit is contained in:
parent
c516afc400
commit
08c95294f6
5 changed files with 97 additions and 4 deletions
|
|
@ -1,5 +1,5 @@
|
|||
class BankAccount:
|
||||
def __init__(self, owner, balance=0):
|
||||
def __init__(self, owner, balance):
|
||||
self.owner = owner
|
||||
self.balance = balance
|
||||
|
||||
|
|
@ -10,7 +10,7 @@ class BankAccount:
|
|||
return False
|
||||
|
||||
def withdraw(self, amount):
|
||||
if 0 < amount <= self.balance:
|
||||
if 0 < amount and amount <= self.balance:
|
||||
self.balance -= amount
|
||||
return True
|
||||
return False
|
||||
|
|
@ -19,7 +19,9 @@ class BankAccount:
|
|||
return self.balance
|
||||
|
||||
def __str__(self):
|
||||
return f"Account({self.owner}, Balance: ${self.balance:.2f})"
|
||||
owner = self.owner
|
||||
balance = self.balance
|
||||
return f"Account({owner}, Balance: {balance})"
|
||||
|
||||
account = BankAccount("Alice", 1000)
|
||||
print(account)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue