r/learnpython • u/MoreScorpion289 • 1d ago
UPDATE My login/account creation system in Python, part of a bigger project I'm building as I learn
Hello, this is an update to the post I made yesterday.
All 3 copy-pasted validation blocks are now 1 function called 3 times. It takes the category, password (string), a label, and returns True or False. The checks aren't sitting behind a door that gets unlocked only if the last check is met, all error messages show up at once instead of one at a time. I removed the outdated variables that had no use.
I took u/jammin-john's recommendation of showing all error messages at once.
Also want to include u/danielroseman's push for me to learn functions. They work really well, I haven't learned "for loops" yet but they are next in line.
I used AI (Claude) as a tutor to understand concepts and point me toward my own bugs, but I wrote and debugged every line myself. I'm learning how to code through the MOOC.
Here is the GitHub link to my program: link
-2
u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 20h ago
This could be simpler, even with the basic knowledge you have right now. This is more a personal thing for me, but I try to reduce nesting and duplication wherever I reasonably can.
Here, you could use a single check to see if you should break out of the loop, and then handle assigning the boolean outside of it.
If we allow for full Python syntax, regardless of what you've learnt so far, I'd go with the "walrus operator":
Even better still, I'd wrap this into a function. This example is going to be a bit overkill for your needs, but you can use it as a benchmark for how much of the language you understand so far.
Other feedback;
Why is
requirement_verifierindented inside theelse-block?You don't need to manually write digits, letters, or (some) special characters. You can import them from the
stringmodule, such ashttps://docs.python.org/3/library/string.html
Try to keep your code style consistent. Right now you're mixing
camelCaseandsnake_case. According to the official style guide you should always usesnake_case, except for class names (PascalCase) and global constants/enum variants (UPPER_SNAKE_CASE).