mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-09-24 23:01:18 +08:00
fix(curriculum): correct validation example in encapsulation lesson (#64906)
Co-authored-by: Jeevankumar <jeeevnkumar2003@gmail.com>
This commit is contained in:
co-authored by
Jeevankumar
parent
8c0f9bf500
commit
0e9f97c581
+7
-5
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user