程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

2024-11(1)

Python123 文本的平均列数

发布于2019-08-07 12:24     阅读(2316)     评论(0)     点赞(4)     收藏(4)


版权声明: https://blog.csdn.net/weixin_44521703/article/details/91128705

题目:文本的平均列数
描述
打印输出附件文件的平均列数,计算方法如下:‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬

(1)有效行指包含至少一个字符的行,不计算空行;‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬

(2)每行的列数为其有效字符数;‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬

(3)平均列数为有效行的列数平均值,采用四舍五入方式取整数进位。

#!/usr/bin/python 3
# -*- coding: UTF-8 -*-

_Author_ = '麦地吃大米'
f= open('latex.log','r')
i= 0
chars = 0
for line in f.readlines():
    # print(i)
    # print(line)
    # print(len(line))
    # i+=1
    # 判断空行
    if not (len(line) == 1  and line[-1]=='\n') :
        i +=1
        chars += len(line)-1

avg = round(chars/i,0)
avg = int(avg)
print(avg)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20


所属网站分类: 技术文章 > 博客

作者:大将军

链接:https://www.pythonheidong.com/blog/article/10760/b10b108dd8c7aa1764d9/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

4 0
收藏该文
已收藏

评论内容:(最多支持255个字符)