热烈祝贺1024,求解Python3.10闪退问题

需求如下图:

img


代码如下:Python3.10,运行程序闪退
请修改直接成可以直接使用
with open('data.txt') as f:
string = f.read()
lines = string.split('\n')
result = []
for line in lines:
count = 0
dist = []
last_index = 0
num_arr = line.split(' ')
for index, num in enumerate(num_arr):
if eval(num) > 0:
count += 1
if last_index:
dist.append(str(index - last_index))
last_index = index
else:
last_index = index
result.append({'count': count , 'dist': dist})
for res in result:
print(f'{res["count"]}个 {" ".join(res["dist"])}')

todo: output to TXT file

python IDLE执行下,检查下错误输出