Cho chuỗi s. Kiểm tra xem chuỗi có chứa ít nhất: 1 chữ số, 1 chữ thường, 1 chữ hoa. (Có thể có ký tự khác).
Ví dụ: "p25KDs" → True.
Cách làm
- Duyệt từng ký tự, cập nhật 3 cờ boolean:
has_digit,has_lower,has_upper. - Trả về
all([has_digit, has_lower, has_upper]).
Ví dụ mã nguồn
def solve(s):
arr = [False]*3
for c in s:
if c.isalnum():
arr[0] = True
if c.islower():
arr[1] = True
if c.isupper():
arr[2] = True
return all(arr)
s = "p25KDs"
print(solve(s)) # True
Đầu vào / Đầu ra
Input: "p25KDs"
Output: True