fix(curriculum): correct validation example in encapsulation lesson (#64906)

Co-authored-by: Jeevankumar <jeeevnkumar2003@gmail.com>
This commit is contained in:
Jeevankumar S
2026-01-05 10:26:23 +01:00
committed by GitHub
co-authored by Jeevankumar
parent 8c0f9bf500
commit 0e9f97c581
@@ -144,13 +144,15 @@ class Wallet:
return self.__balance
acct_one = Wallet()
acct_one.deposit(4) # ValueError('Amount must be positive')
print(acct_one.get_balance()) # 0
acct_one.deposit(3)
print(acct_one.get_balance()) # 3
acct_one.deposit(50)
print(acct_one.get_balance()) # 50
acct_one.withdraw(-8) # ValueError('Amount must be positive')
acct_one.withdraw(58) # ValueError('Insufficient funds')
print(acct_one.get_balance()) # 53
acct_one.deposit(-4) # ValueError: Amount must be positive
acct_one.withdraw(-8) # ValueError: Amount must be positive
acct_one.withdraw(58) # ValueError: Insufficient funds
```
As you can see, the `__validate` method is private, and runs behind the scenes in the `deposit()` and `withdraw()` public methods to make sure the amount is always valid.