老男孩python全栈s21day25作业

一、正则表达式练习

1、匹配整数或者小数(包括正数和负数)
\-?\d+(\.\d+)?
2、匹配年月日日期 格式2018-12-6
\d{1,4}\-\d{1,2}\-\d{1,2}
3、匹配qq号
[1-9]([0-9]{5,11})
4、11位的电话号码
^1(3|4|5|7|8)\d{9}$
5、长度为8-10位的用户密码 : 包含数字字母下划线
\w{8,10}
6、匹配验证码:4位数字字母组成的
([\d]|[a-z]|[A-Z]){4}
7、匹配邮箱地址
[\w]{1,}\@([a-z]|[A-Z]){1,}\.com
8、1-2*((60-30+(-40/5)(9-25/3+7/399/42998+10568/14))-(-43)/(16-3*2))从上面算式中匹配出最内层小括号以及小括号内的表达式
\(\-?\d{1,}([\*|\+|\-|\/]\-?\d{1,}){1,}\)
9、从类似9-25/3+7/399/42998+10568/14的表达式中匹配出乘法或除法
\-?\d{1,}([*|\/]\-?\d{1,}){1,}
10、从类似
<a>wahaha</a>
<b>banana</b>
<h1>qqxing</h1>

这样的字符串中,
1)匹配出,,

这样的内容

(\<a\>)|(\<b\>)|(\<h1\>)

2)匹配出wahaha,banana,qqxing内容。(思考题)

import re

content = '''<a>wahaha</a>
<b>banana</b>
<h1>qqxing</h1>'''
print(content)
ret = re.split('<\/?\w{1,}>\n?',content)
for item in ret:
    if item != '':
        print(item)

自学以下内容,完成10、2)

https://www.cnblogs.com/Eva-J/articles/7228075.html#_label10

ret = re.search("<(?P<tag_name>\w+)>\w+</w+>",“

hello

”)
#还可以在分组中利用?的形式给分组起名字
#获取的匹配结果可以直接用group(‘名字’)拿到对应的值
print(ret.group(‘tag_name’)) #结果 :h1
print(ret.group()) #结果 :

hello

二、使用listdir完成计算文件夹大小

# 1.递归
# 2.堆栈  递归函数-三级菜单
import os
def get_path_list(dirname):
    '''
    传入目录名,返回该目录下所有的文件夹河文件的列表。
    :param dirname:
    :return:
    '''
    path_list = []
    if os.path.isdir(dirname):
        ret = os.listdir(dirname)
        for item in ret:
            result = os.path.join(dirname,item)
            path_list.append(result)
            for j in get_path_list(result):
                path_list.append(j)
    return path_list

def get_file_size(dirname):
    return os.path.getsize(dirname)


dirname = r'E:\python\pythoncode\pythonhomework\day02-20190707'
path_list = get_path_list(dirname)
file_size = 0
for item in path_list:
    file_size += get_file_size(item)
print("文件夹%s的大小为:%sKB"%(dirname,file_size))

三、根据以下需求,完成选课系统作业,2019年5月4号晚上10点之前提交

https://www.cnblogs.com/Eva-J/articles/9235899.html

正在编写ing。。。。。。

参考链接:https://gitee.com/old_boy_python_stack_21/teaching_plan/issues/IW3BK

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值