Aufgabe3 : oop lösungen #3
28
codewars/banking_system.py
Normal file
28
codewars/banking_system.py
Normal file
@ -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}."
|
||||||
Loading…
x
Reference in New Issue
Block a user