+ 2

Code Coach: More Metacharacters (Python - RegEx) - Solution is incomplete

Hi, since there is no button to report incorrect solutions in CodeCoach, I will post this as a topic of discussion. In short: The regular expression r"\w*[A-Z]\w*[0-9]\w*" given in the model solution does not fit if the user decides to create a password where the number precedes the capital letter, e.g. "jskjf2klsjdDlk". You can use my playground code to see for yourself: https://www.sololearn.com/compiler-playground/ceKj74ci8AAX --------------------------------------------------------------------------------- Here is the task description: (copied) More Metacharacters Let's imagine we are creating our own authentication system. 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. Sample Input Hal44gb8 Sample Output Password created -------------------------------------------------------------------------------- This is the given solution (Excuse me, if there are any typos, I could not copy it) import re password = input() pattern = r"\w*[A-Z]\w*[0-9]\w*" if re.match(pattern, password): print("Password created") else: print("Wrong format")

17th Sep 2022, 10:57 AM
couscous
6 Respuestas
+ 6
couscous , we had a discussion about the same task, have a look on it: Jayakrishna🇮🇳 has made a good explanation about how the regex pattern should be. Ani Jona has also made a suggestion that should work: pattern = r"[A-Z].*\d|\d.*[A-Z]" https://www.sololearn.com/Discuss/3083841/?ref=app
17th Sep 2022, 7:39 PM
Lothar
Lothar - avatar
+ 3
Jayakrishna🇮🇳 , it is python core, lessen 86.2
18th Sep 2022, 1:59 PM
Lothar
Lothar - avatar
+ 3
Lothar Jayakrishna🇮🇳 The issue is NOT about which regex passes the test cases but about the TASK DESCRIPTION. The task description states 2 criteria. It is unclear form the text if the criteria must be met in exact that order of if the order does not matter. From the model solution and the test cases it may be inferred that the only the order "letter-digit" is required.
18th Sep 2022, 2:09 PM
Lisa
Lisa - avatar
+ 2
We cannot see what you wrote in the code tab. You would need to save it in a script on sololearn playground and link it here. I agree that the task description is mistakable: It could be understood that the 2 criteria may be met in arbitrary order, however the test cases only seem to test them as if they were ordered. https://code.sololearn.com/crSQq2Oj51mL/?ref=app
17th Sep 2022, 11:57 AM
Lisa
Lisa - avatar
+ 2
@Lother OP have solution already... But couscous which code coach are about? Can you add link..? One I know is, asks write solution by regex by us. But there is no model solution.
17th Sep 2022, 9:07 PM
Jayakrishna 🇮🇳
+ 2
Thank you all! That answers my question!
26th Sep 2022, 9:24 AM
couscous