Skip to content

Commit 0e9f97c

Browse files
Jeevankumar-sJeevankumar
andauthored
fix(curriculum): correct validation example in encapsulation lesson (freeCodeCamp#64906)
Co-authored-by: Jeevankumar <[email protected]>
1 parent 8c0f9bf commit 0e9f97c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

curriculum/challenges/english/blocks/lecture-understanding-object-oriented-programming-and-encapsulation/68420be9af9d89620af7944a.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,15 @@ class Wallet:
144144
return self.__balance
145145

146146
acct_one = Wallet()
147-
acct_one.deposit(4) # ValueError('Amount must be positive')
148-
print(acct_one.get_balance()) # 0
147+
acct_one.deposit(3)
148+
print(acct_one.get_balance()) # 3
149149

150150
acct_one.deposit(50)
151-
print(acct_one.get_balance()) # 50
152-
acct_one.withdraw(-8) # ValueError('Amount must be positive')
153-
acct_one.withdraw(58) # ValueError('Insufficient funds')
151+
print(acct_one.get_balance()) # 53
152+
153+
acct_one.deposit(-4) # ValueError: Amount must be positive
154+
acct_one.withdraw(-8) # ValueError: Amount must be positive
155+
acct_one.withdraw(58) # ValueError: Insufficient funds
154156
```
155157

156158
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.

0 commit comments

Comments
 (0)