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")

22nd Apr 2022, 4:37 PM
Carmilla Boykin
Carmilla Boykin - avatar
4 Réponses
+ 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.
22nd Apr 2022, 7:49 PM
#0009e7 [get]
#0009e7 [get] - avatar
+ 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."""
22nd Apr 2022, 7:51 PM
#0009e7 [get]
#0009e7 [get] - avatar
+ 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.
22nd Apr 2022, 8:52 PM
Carmilla Boykin
Carmilla Boykin - avatar