gpt4 book ai didi

Python 一个统计文件行数和字符数的函数

转载 作者:行者123 更新时间:2023-11-28 21:51:46 25 4
gpt4 key购买 nike

<分区>

谁能看看我到目前为止做了什么?我自己还没成功定位到问题。

def txt_file(file1):
file1 = open('text.txt', 'r')
linecount = 0
charcount = 0
for line in file1:
linecount +=1
for char in line:
charcount += 1
print "file1 contains", linecount, "lines and", charcount, "characters."
file1.close()

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com