Python编程快速上手——让繁琐工作自动化第七章实践题

##7.18.1

import re

def yanzheng(zifu):
    if len(zifu) < 8:
        print('密码长度不足8位')
    elif re.compile(r'[A-Z]').search(mima) == None:
        print('密码中须包含大写字母')
    elif re.compile(r'[a-z]').search(mima) == None:
        print('密码中须包含小写字母')
    elif re.compile(r'\d').search(mima) == None:
        print('密码中须包含数字')
    elif re.compile(r'\s').search(mima) != None:
        print('密码中不能有空格')
    else:
        print('密码设置成功')

print('请输入密码')
mima = input()
yanzheng(mima)

##7.18.2

import re
def hanshu(a, b = None):
    if b == None:
        shanchu = re.compile(r'^\s+.*\s$', re.DOTALL)
    else:
        shanchu = re.compile(r''+b+'', re.I)
    a = shanchu.sub('', a)
    print('删除后字符串为:' + a)
str1 = input('请输入字符串: \n')
zifu = input('请输入需删除的字符: \n')
hanshu(str1, b = zifu)

你可能感兴趣的:(Python编程)