Python Learning: Automate Boring Stuff with Python | Solution to Part II Chapter 7 Practice Project I

[sourcecode language=”python”]</pre>

import re import re 
#eight chars long #upper and lower case chars #at least one digit

patternHasDigit = re.compile(r"\d+")
patternHasLower = re.compile(r"[a-z]+")
patternHasUpper = re.compile(r"[A-Z]+")

patterns = (patternHasDigit, patternHasLower, patternHasUpper)
tests = ["asdfgh57887", "Asfkg35a", "23454990-","ASHGFDSFGHFDSDFGDS"]
for test in tests:
status = True for pattern in patterns:
if == None:
print("{} failed {} test".format(test, pattern.pattern))
status = False if status: print("{} did match".format(test))
else: print("{} did not match".format(test)) status = True


Please follow and like us:

Enjoy this blog? Please spread the word :)

error: Content is protected !!