Let’s say there is a random string. If it does not contain at least one uppercase or lowercase character or number, then correct it in such a way that after the correction there will be at least one uppercase character, at least one lowercase character and any number. How can you do this without a lot of if’s, but without changing the line length?
Well, I got it in four
ifs (in general, I could have merged everything into one huge one, but this is somehow too much). Yes, this option is quite long, but still appropriate. Here’s why: numbers and upper and lower case letters are added when necessary , not always (that is: if there is no number, then it is added). If you need it for passwords, then this option will do. Only here in
else-s you need to modify it by adding random. Well, it’s not that hard anymore.
Highlights of the code:
2. Checking for its length
3. Checking for the content of numbers
4.Checking for the content of small and capital letters (small letters have a slight difference in checking: since numbers are also small characters, then a comparison is made with a long list of numbers contained in the string)
5. Correcting the string in accordance with the above
string = input ('') if len (string) & gt; 2: if len ([s for s in string if s in list ('1234567890')]) & gt; 0: if len ([s for s in string if s.islower ()]) & gt; len ([s for s in string if s in list ('1234567890')]: if len ([s for s in string if s.isupper ()]) & gt; 0: pass else: string = list (string) string  = 'I' string = '' .join (string) else: string = list (string) string  = 'z' string = '' .join (string) else: string = list (string) string  = '8' string = '' .join (string)