Use a dictionary (or set) as a fast lookup table to reject well-known weak passwords.
You start with:
common = {"password": True, "123456": True, "qwerty": True, "letmein": True}
password = "qwerty"
Build:
Password: qwerty Common: True Weak: reject
Rules:
- Collect the output lines in a variable named
receipt: one string with the lines joined by"\n"(for example build a listlinesand join it). The grader printsreceiptfor you, so do not callprint. - Add the line
"Password: "followed by the password. - Look the password up in the dictionary
commonand store the result as a boolean (theinoperator checks a dictionary's keys). - Add the line
"Common: "followed by the boolean. - If it is common, add the line
"Weak: reject"; otherwise add the line"Strong: accept".
Try other passwords: with Tr0ub4dor the output is
Password: Tr0ub4dor Common: False Strong: accept
password in common gives the boolean directly.
common = {"password": True, "123456": True, "qwerty": True, "letmein": True}
password = "qwerty"
lines = []
lines.append("Password: " + password)
is_common = password in common
lines.append("Common: " + str(is_common))
if is_common:
lines.append("Weak: reject")
else:
lines.append("Strong: accept")
receipt = "\n".join(lines)
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
