0
Python Core: More Metacharacters: Practice: Authentication
Hi, I had a bit of an issue with this practice activity in the Python Core course. This one is bugging me. I eventually looked at the solution, and the pattern was stated to be this: pattern = r"\w*[A-Z]\w*[0-9]\w*" I was thinking it was this way: pattern = r"[A-Z]+[0-9]+" Why doesn't my method work, and how does the solution work?
4 odpowiedzi
+ 3
The pattern takes any word characters characters and yours does not
+ 2
Also, fun fact, "/w" is not taught until the section after that Code Coach challenge. This isn't the first time Sololearn is throwing in concepts into challenges that we haven't learned yet. (ㆆ_ㆆ)
+ 2
If you want to make use of "+" you can definitely do that in this way:
import re
password = input()
#your code goes here
pattern1 = r"[A-Z]+"
pattern2 = r"[0-9]+"
if re.search(pattern1, password) and re.search(pattern2,password):
print("Password created")
else:
print("Wrong format")
However as you can see you 'll need to use 2 different patterns which will make the code a bit longer
0
Thanks Slick! What you say makes sense, and maybe I'm thinking it should be a combination of both. The part I don't get is why we don't have to declare "one or more of" with "+" or "{1,}"? The problem is asking for there to be at least one uppercase letter and one number.