26th Feb 2020, 7:53 AM
Taraash Mittal
Taraash Mittal - avatar
5 Answers
+ 4
I saw that you have started with coding short time ago. Taking this in account, you did a remarkable job with your code. Now you should practice more and more, and also take a look on what you have done so far. I am sure you notice that there is some repetition in your code. The majority of your code is multiple repeated, except 4 values and and an additional print statement. Take this hard-coded values out from the code in a variable (list or a dictionary), and run all the count stuff in a loop. You will save appr. 80% of your code. Later you can also get one step ahead by only counting the used characters, digits and special characters. Try to learn this kind of optimization with a smaller code as the ones you have shown here. I am sure you are on a good way.
26th Feb 2020, 9:44 AM
Lothar
Lothar - avatar
+ 2
Hi, it is nothing wrong with looking other coders over the shoulder. Find some solutions on code playground and study them. It is a good kind of practice.
26th Feb 2020, 7:56 AM
Oma Falk
Oma Falk - avatar
+ 1
I admit being too lazy to go through your entire code to see what it is what you want to do with it, but I have added a simple bit of code I wrote that checks validation of a password. perhaps you can find some inspiration in it. https://code.sololearn.com/cPtX5ayvoRwy/?ref=app also kind tip: perhaps don’t say to your user: “what were you thinking?” sounds a bit derisive and hostile. also, why are you first blanking the pw with Xs only to then print the full pw lower down?
26th Feb 2020, 9:35 AM
Brave Tea
Brave Tea - avatar
0
Thanks Lothar, I tried to make it shorter by putting these values in different variable, but that didn't work
26th Feb 2020, 5:16 PM
Taraash Mittal
Taraash Mittal - avatar
0
a good rule of thumb is: everytime you are repeating code (for example, count ) you should/could take a look into doing it shorter (perhaps make a function that you can use again, or perhaps find a different built-in function to the ones you are using now) also everytime you are using any number or string as an argument more than once or twice it should go into a variale
26th Feb 2020, 6:03 PM
Brave Tea
Brave Tea - avatar