+ 2

Exercise 4.2 "Authentification" doesn't test correctly

import re password = "Gek1911" pattern = r"([A-Z])+([a-z])*([0-9])+" if re.search(pattern,password): print("Password created") else: print("Wrong format") Returns "password created" in test "lgh1411" when in other parsers returns "wrong format"

5th Jun 2021, 5:24 AM
Mariano Belgrano 🇦🇷
Mariano Belgrano 🇦🇷 - avatar
12 Réponses
+ 1
"lgh1411" return "wrong format" with your code ^^ however, "lGh1411" or "Lgh1411x" both return "password created" but they shouldn't ;P you must use 'fullmatch" to test if whole string fulfill the pattern (or add start and end anchors in your pattern) ;)
5th Jun 2021, 5:40 AM
visph
visph - avatar
+ 1
“however, "lGh1411" or "Lgh1411x" both return "password created" but they shouldn't ;P” Yes they should return “password created” as the assignment asks at least one capital letter and one number
5th Jun 2021, 7:20 AM
Mariano Belgrano 🇦🇷
Mariano Belgrano 🇦🇷 - avatar
+ 1
In lGh1411 the string Gh1411 matches the pattern similarly in Lgh1411x, the matching string is Lgh1411. wrap your regex between ^ and $ which ensures that the input should definitely match the whole string
5th Jun 2021, 7:35 AM
Aravind Shetty
Aravind Shetty - avatar
+ 1
it is referenced as 4.2 Practice "Authentification" for me (after the 4.1 Lesson "More Metacharacters")...
5th Jun 2021, 7:44 AM
visph
visph - avatar
+ 1
That was the hardest practice so far in this course, waw
23rd Aug 2021, 7:26 PM
Khalil
Khalil - avatar
0
Mariano Belgrano 🇦🇷 I assumed that your regex was valid: start with 1 or more capital letter, followed by 0 or more lowercase letter, followed by 1 or more digit... wich could make sense, since you doesn't provide the full problem requirements...
5th Jun 2021, 7:24 AM
visph
visph - avatar
0
The full problem requirement is published in python core curse. The parser which evaluates the code has a bug I guess since differs with other parsers. Please check it
5th Jun 2021, 7:27 AM
Mariano Belgrano 🇦🇷
Mariano Belgrano 🇦🇷 - avatar
0
is this the 4.2 practice? if so, that's a 'pro' code coach, and I do not have access to it ^^ anyway, do you think we are smart enough to guess what is the code coach problem you're trying to do? without providing accurate informations, you cannot expect get accurate answers ;P
5th Jun 2021, 7:34 AM
visph
visph - avatar
0
I didn’t know it was not visible to everybody. My apologies. Bu the way as this forum is a shortcut inside the course now I realize is wide open to the entire platform
5th Jun 2021, 7:38 AM
Mariano Belgrano 🇦🇷
Mariano Belgrano 🇦🇷 - avatar
0
87.2 Authentication is the name of the exercise
5th Jun 2021, 7:39 AM
Mariano Belgrano 🇦🇷
Mariano Belgrano 🇦🇷 - avatar
- 1
The above pattern will match if you give a uppercase letters, lowecase letters, numbers in an order. otherwise it doesn't match. if you want to validate a password, the easy way is to create different regexes and test with every regex [a-z]+, [A-Z]+, [0-9]+ you can also have a one regex using look aheads, like this, ^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#$%^&*()_+=|\><.,?/-])[A-Za-z0-9!@#$%^&*()_+=|\><.,?/-]{8,}$ which ensure that you have atleast one lower case, one uppercase, one number and one special character.
5th Jun 2021, 7:15 AM
Aravind Shetty
Aravind Shetty - avatar
- 1
Here's what worked for me: import re password = input() #your code goes here pattern = r"([A-Z,0-9])+" if re.match(pattern, password): print("Password created") else: print("Wrong format")
8th Feb 2022, 9:24 AM
Silvie Skalická