28 lines
953 B
Python
28 lines
953 B
Python
class User:
|
|
def __init__(self, name, balance, checking_account):
|
|
self.name = name
|
|
self.balance = balance
|
|
self.checking_account = checking_account
|
|
|
|
def withdraw(self, amount):
|
|
if amount > self.balance:
|
|
raise ValueError("Not enough money")
|
|
|
|
self.balance -= amount
|
|
return f"{self.name} has {self.balance}."
|
|
|
|
def add_cash(self, amount):
|
|
self.balance += amount
|
|
return f"{self.name} has {self.balance}."
|
|
|
|
def check(self, other_user, amount):
|
|
if not other_user.checking_account:
|
|
raise ValueError("User has no checking account")
|
|
|
|
if other_user.balance < amount:
|
|
raise ValueError("Not enough money")
|
|
|
|
other_user.balance -= amount
|
|
self.balance += amount
|
|
|
|
return f"{self.name} has {self.balance} and {other_user.name} has {other_user.balance}." |