0
Code coach practice authentication
Iām confused why is it saying my code is wrong? I am meeting the requirements but only two pass and two fail the sample inputs. import re password = input() pattern = r"[A-Z]+[0-9]+" if re.search(pattern, password): print("Password created") else: print("Wrong format")
4 Answers
+ 4
It is not necessarily that it should be "uppercase, digit". It could also be "digit, uppercase" and even neither of those, but always having some other characters (lowercase (or symbols such as "-", "_", "*", "quot;?)) between those possible sequences. So, my suggestion is to check for either (or both) "uppercase, other characters, digit" and "digit, other characters, uppercase" sequences.
+ 3
[Person who asked to clarify the task and deleted the answer], no. I think, they either misunderstood it or do not have enough experience with regular expressions to normally work with them in most of cases.
The original description is:
"""Create a program that takes a password as input and returns "Password created" if
- it has at least one uppercase character
- it has at least one number
The Program should output "Wrong format" if requirements above are not met."""
+ 2
Thanks you i figured it out.
What i had was..
import re
password = input()
pattern = r"[A-Z]+[0-9]+"
if re.search(pattern, password):
print("Password created")
else:
print("Wrong format")
Then after going through about an hour of google, other examples, and reviewing notes i realized to make my code work i had to add to the pattern section. Should be
pattern = rā[A-Z]+[a-z]*[0-9]+ā
That small changed fixed it. Thanks for help though.