判断字符串是否合法

要求:必须有数字和字母且只能有数字和字母,并且第一个字符是大写字母

strs = input()
digit = 0
if 65 <= ord(strs[0]) <= 90:
    for s in strs[1 : ]:
        if s.isdigit():
            digit = 1
            continue
        elif s.isalpha():
            continue
        else:
            print('不合法')
            break
    else:
        if digit == 0:
            print('不合法')
        else:
            print('合法')
else:
    print('不合法')

发布了84 篇原创文章 · 获赞 10 · 访问量 8556

猜你喜欢

转载自blog.csdn.net/AK47red/article/details/104319825