جواب «Step 4: The Verdict» چالش 4 از جلسهی 12
سؤال
آخرین قدم: اگر رمز (کوچکشده) در common بود، امتیاز 0 شود و missing فقط not a common password باشد. بعد حکم بده: امتیاز کمتر از 12 → verdict: WEAK، کمتر از 20 → verdict: MEDIUM، وگرنه verdict: STRONG. خروجی: score، missing، verdict در سه خط.
راهنما
if password.lower() in common: score = 0; missing = ["not a common password"] و بعد if/elif/else برای حکم.
یک جواب درست
common = ["123456", "password", "qwerty", "111111", "password1"]
password = input()
upper = lower = digit = symbol = 0
for ch in password:
if ch.isupper():
upper += 1
elif ch.islower():
lower += 1
elif ch.isdigit():
digit += 1
else:
symbol += 1
score = len(password)
missing = []
if upper > 0:
score += 3
else:
missing.append("a capital letter")
if lower > 0:
score += 3
else:
missing.append("a small letter")
if digit > 0:
score += 3
else:
missing.append("a digit")
if symbol > 0:
score += 3
else:
missing.append("a symbol")
if len(password) < 12:
missing.append("more length (12+)")
if password.lower() in common:
score = 0
missing = ["not a common password"]
print("score:", score)
print("missing:", missing)
if score < 12:
print("verdict: WEAK")
elif score < 20:
print("verdict: MEDIUM")
else:
print("verdict: STRONG")
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن