r/PythonLearning • u/Ok-Paper540 • Sep 06 '25
day 4 of learning python
I just started my first small project, implementing what I’ve learned so far. I recently began learning about the def statement, so I'm not sure if I'm using it correctly. Any tips would be appreciated, im coding for about 2/3 hours a day using the book 'automate the boring stuff with python' second edition . this my first ever reddit post so it feels weird sharing my progress and if im on the right track.
2
u/kjrusse Sep 06 '25
I'm not a very experienced Python coder, but I'm confused as the code references self.accountBalance and self.balance in the class functions. I see that current amounts are added to self.balance and debts are removed from self.balance, but the account was initialized with self.accountBalance and the balance query also references self.accountBalance so I'm not sure where self.balance comes from??? Absolutely no offense meant at all, just trying to understand.
2
u/JaleyHoelOsment Sep 07 '25
good catch. those methods would fail. OP just hasn’t called them here so hasn’t fixed that issue yet.
2
u/Ok-Paper540 Sep 07 '25
thank you for letting me know in advance ill fix them when i get the chance =)
1
u/JaleyHoelOsment Sep 07 '25
also OP, in your code, no matter what name i enter it will always call me Billy!
2
u/MuaKuZ Sep 06 '25
why is line 41 != and not == i am new and i dont get it
6
u/CaptainRift Sep 06 '25
It's because of the 'continue' on line 42. Continue ends the current iteration of a loop while still continuing the loop.
In this case, if the if statement is true (name != accountHolder) it will end the current iteration of the loop meaning it won't run lines 43 onwards.
You could use == but then you'd have to move line 43 and 44 inside the if statement, and make an else statement that will keep looping until the name is correct or the code is exited.
2
u/MuaKuZ Sep 06 '25
thanks this was very usefull ...@CaptainRift your explanation very useful/helpful thx a lot
1
Sep 06 '25
Nice 👏
Keep learning and keep it up. BTW you’re referencing something that does not exist - self.accountName has not been defined 😅
1
1
u/Bonsai2007 Sep 07 '25
Looks good, but you habe an error in Line 28 self.accountName should be self.accountNumber. And why do you import sys? I can’t see the usage of the module, maybe I haven’t seen it 🤔
1
1
1
u/VonRoderik Sep 08 '25
Shouldn't he instantiate an object?
account1 = bankAccount()
account1.accountnumber = 1231231
u/Mean-Lengthiness-741 Sep 10 '25
I’ll try to express myself in english, but probably it’ll have some mistakes.
Usually I prefer to use dicts as arguments to my init functions, using the **kwargs as the input and the get method inside the init, with that way it’s easier to handle the function input errors, and to visualize what are u is given to the class.
In your case will be something like: “”” def init(self, **client): self.account_number = client.get(“account_number”, None) … “”” other thing, i rather to use the snake case for the variables and function names, using the camel case just for class names.
1
0
u/oldranda1414 Sep 07 '25
Great job, everything looks good
A minor detail is that class names are usually in CamelCase, so your class should be called 'BankAccount', not bankAccount
This is just a convention so it's no code breaking bug, but conventions help your code being readable amd undestandable means you can get more help on improving from others
If you are curious here you can find python's style guide, but it might be a little too in depth for someone at your level so don't be discouraged if you don't understand everything :)
1
u/Ok-Paper540 Sep 07 '25
ill definitely give it a read even if i cant understand it hopefully i could get something out of it
2
u/ConnectionWorking207 Sep 07 '25
What book are you using?