十二道python编程题,有答案(计算文件大小、三级菜单、文件监听、发红包

# 将括号内的加减法都匹配出来
res_lis = re.findall('[-+]?\d+(?:\.\d+)?',res1)
print(res_lis)  # ['9', '-3.3333333333333335', '+173134.50000000003', '+405.7142857142857']
sum_n = 0
for i in res_lis:
    sum_n += float(i)
return sum_n

def remove_bracket(express):
while True:
# 提取表达式最里层的括号
exp = re.search(‘([^()]+)’,express)
if exp:
res = exp.group() # (9-2*5/3+7/3*99/4*2998+10*568/14)
rep = cal_no(res) # 173545.88095238098
print(rep)
express = express.replace(res,str(rep)) # 因为rep的结果是一个数字
print(express) # 1-2*((60-30+173545.88095238098*(-40/5))-(-4*3)/(16-3*2))
else:break
return express # 括号内的表达式全部计算完成1-2*-1388338.2476190478
ret = remove_bracket(express)
print(cal_no(re


#### 八、校验文件的一致性



import os

import hashlib

def file_md5(path):

filesize = os.path.getsize(path)

md5 = hashlib.md5()

with open(path,‘rb’) as f:

while filesize >= 4096:

content = f.read(4096)

md5.update(content)

filesize -= 4096

else:

content = f.read(filesize)

if content:

md5.update(content)

return md5.hexdigest()

def cmp_file(path1,path2):

return file_md5(path1) == file_md5(path2)

path1 = r’D:\s20\day18\视频\4.面向对象整理.mp4’

path2 = r’D:\s20\day18\视频\tmp.mp4’

ret = cmp_file(path1,path2)

print(ret)


#### 九、打印九九乘法表



for i in range(1,10):
for j in range(1,i+1):
print(“%s*%s=%s”%(i,j,i*j),end=’ ')
print()

for i in range(1,10):
for j in range(i,10):
print(“%s*%s=%s”%(i,j,i*j),end=’ ')
print()


#### 十、购物车作业



创建一个名为‘购买账单的txt文件’

goods = []
money = input(‘请充值充值金额’).strip()
with open(‘商品信息’,encoding=‘utf-8’)as f:
for i in f:
xinxi = i.strip().split(’ ')
if xinxi[0] == ‘name’:
continue
else:
dic = dict([(‘name’,xinxi[0]),(‘price’,xinxi[1])])
goods.append(dic)
print(goods)
“”"
页面显示 序号 + 商品名称 + 商品价格
“”"
a = 1
for v in goods:
print(a,v[‘name’],v[‘price’])
a += 1
print(‘n 购物车结算’)
print(‘q 或 Q 退出’)
shop_dic = {}
s

  • 12
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值