Invalid password
The second part of the website project is to write a script that validates the password entered by the user. The company also puts some rules in order to verify valid passwords:
- It can contain lowercase
a-zand uppercase lettersA-Z - It can contain numbers
- It can contain the symbols:
*,#,$,%,!,&,. - It must be at least 8 characters long but not more than 20
Your colleague also gave you a list of passwords as examples to test.
The list passwords and the module re are loaded in your session. You can use print(passwords) to view them in the IPython Shell.
이 연습은 강의의 일부입니다
Regular Expressions in Python
연습 안내
- Write a regular expression to check if the passwords are valid according to the description.
- Search the elements in the
passwordslist to find out if they are valid passwords. - To print out the message indicating if it is a valid password or not, complete
.format()statement.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Write a regex to check if the password is valid
regex = ____"[____]____"
for example in passwords:
# Scan the strings to find a match
if re.____(____, ____):
# Complete the format method to print out the result
print("The password {____} is a valid password".format(pass_example=____))
else:
print("The password {____} is invalid".format(pass_example=____))