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()
会计专业数据分析作业,处理TXT数据文件
于 2021-12-07 19:08:27 首次发布