1. 字符串检测:检测用户输入的字符串是否符合以下条件: (a)长度大于6; (b)包含大写字母; (c)包含小写字母 (d)包含数字; (e)包含标点符号( : , . ? ; ‘ “ !

  1. 字符串检测
    【问题描述】检测用户输入的字符串是否符合以下条件:

(a)长度大于6;

(b)包含大写字母;

(c)包含小写字母

(d)包含数字;

(e)包含标点符号( : , . ? ; ’ " ! )。

若全部满足条件请输出“correct”,否则输出“wrong”。

【输入形式】字符串
【输出形式】correct / wrong

【样例输入】abc895
【样例输出】wrong

【样例说明】任意字符串。
【评分标准】

使用正则表达式可解:

import re
s=input()
print('correct' if len(re.findall(r'[a-z]', s))>0 and len(s)>6 and len(re.findall(r'[0-9]', s))>0 and len(re.findall(r'[A-Z]', s))>0 and len(re.findall(r'[\':,.?;"!]', s))>0 else 'wrong')

猜你喜欢

转载自blog.csdn.net/missionnn/article/details/120450318
今日推荐