会计专业数据分析作业,处理TXT数据文件

import re
import time
from typing import Optional, Match

name = "                      刘璐"


class ITEM:
    a = 0
    b = 1
    with open("item.txt", encoding='utf-8', mode="r") as item:
        data = item.readlines()
        x = len(data)
    while a == 0:
        profit = 0
        for y in range(x - 1):
            diyi = data[y]  # 读取一行
            b += 1
            if b == x:
                a = 1
            if diyi == "\n":
                continue
            cost = re.findall(r'[1-9]+\.?[0-9]*', diyi)  # 匹配这一行的数字
            re_words = re.compile(u"[\u4e00-\u9fa5]+")
            m: Optional[Match[str]] = re_words.search(diyi, 0)
            select_list = ["收入"]
            time.sleep(0.3)
            if "收入" in m.group():
                if int(profit) > 0:
                    print("利润为:" + str(profit))
                print("--------------------------------------")
                profit = 0
                profit = cost[0]
            if b == x:
                a = 1
            else:
                profit = int(profit) - int(cost[0])
            print(m.group() + "的金额为:" + cost[0])

        print("利润为:" + str(profit))
        print(name)
        input()


if __name__ == '__main__':
    ITEM()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

~RD XIAO Du

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值