بتل کد Battle Codeدارد باز می‌شود…

جواب «Strength Checker» چالش 5 از جلسه‌ی 7

سؤال

(سخت‌تر) برنامه‌ای بنویس که یک رمز (ساختگی!) با input بگیرد و امتیاز بدهد: اگر طولش ۱۲ یا بیشتر بود 2 امتیاز، اگر رقم داشت 1 امتیاز، اگر حرف بزرگ داشت 1 امتیاز. چاپ کن score: 3 و در خط بعد اگر امتیاز ۳ یا بیشتر بود strong، وگرنه weak: make it longer.

راهنما

سه if برای امتیاز: if len(password) >= 12: score = score + 2 و دو تا برای has_digit و has_upper. بعد print("score:", score).

یک جواب درست

password = input()
score = 0
has_digit = False
has_upper = False
for ch in password:
    if ch.isdigit():
        has_digit = True
    if ch.isupper():
        has_upper = True
if len(password) >= 12:
    score = score + 2
if has_digit:
    score = score + 1
if has_upper:
    score = score + 1
print("score:", score)
if score >= 3:
    print("strong")
else:
    print("weak: make it longer")

اول خودت امتحان کن؛ جواب‌های دیگر هم قبول است. برگرد و خودت حلش کن