diff --git a/codewars/banking_system.py b/codewars/banking_system.py new file mode 100644 index 0000000..d4bedbe --- /dev/null +++ b/codewars/banking_system.py @@ -0,0 +1,28 @@ +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}." \ No newline at end of file