From 0ba836206b815c5faaad5e08ebe1a6a4297c9904 Mon Sep 17 00:00:00 2001 From: Ola Hamza Date: Sun, 15 Mar 2026 19:03:48 +0100 Subject: [PATCH] add classy banking system solution --- codewars/banking_system.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 codewars/banking_system.py 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