I'm trying to make a password checker in python. Is there a way of preventing a user from entering 2 consecutive lower case characters without using regex? Thanks
def detectConsecutiveLowerCase(s): if not s or s == '': return False # this keeps the status of last character prevLower = s[0].islower() for i in range(1, len(s)): # if current as well as previous character was # lowercase if s[i].islower() and prevLower: return True # update the status to current character's prevLower = s[i].islower() # if we reached here, then no consecutive lowercase # existed return False print(detectConsecutiveLowerCase('ThiWiLlBeCaUgHt')) print(detectConsecutiveLowerCase('tHiSWiLlNOTBeCaUgHt'))
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.
Get Answers For Free
Most questions answered within 1 hours.