Kodax

حساب بنكي مغلّف — تحدي Python

أنشئ صنف BankAccount يخزن الرصيد في خاصية خاصة __balance. الدالة deposit(amount) تضيف مبلغاً موجباً فقط، وwithdraw(amount) تسحب إذا كان الرصيد يكفي وتُرجع True، وإلا تُرجع False بدون تغيير. الخاصية balance (property) تُرجع الرصيد للقراءة فقط.

class BankAccount:
    def __init__(self, owner, balance=0):
        # خزّن الرصيد في self.__balance
        pass

    def deposit(self, amount):
        pass

    def withdraw(self, amount):
        pass

    @property
    def balance(self):
        pass

حل هذا التحدي يرتبط بفتح دورة «البرمجة الكائنية» بحسابك.

ابدأ الحل