Problem with Authentication! Practice in Python Core?
Am I mistaken or is there a flaw in the provided solution of this practice problem? The premise is that a user imputed password should contain at least one uppercase letter as well as one number. The provided solution is: if re.search(r"[A-Z][0-9]*",input()): print("Password created") else: print("Wrong format") Since the (*) metacharacter means 0+ repetitions the password doesn't actually need to have a number in it, it would match any password as long as it has a capital letter. I first thought that the correct solution was to replace the (*) with a (+) as the (+) metacharacter looks for 1+ repetitions. I.E. if re.search(r"[A-Z][0-9]+",input()): However this still doesn't work as it requires the password to have a capital letter that is immediately followed by a number. So A3xample works but Aexampl3 does not. I'm aware that there are ways to do this using look ahead however as this hasn't been covered in the lessons so far my solution was to create an 'if and' statement. password = input() if re.search(r'[A-Z]+',password) and re.search(r'[0-9]+',password): print('Password created') else: print('Wrong format') Am I correct that this provided answer is flawed or am I missing something? Additionally is there a more efficient solution that doesn't involve look ahead? Any input is appreciated.