小编BFo*_*e01的帖子

如何打开文件并找到最长的一行,然后将其打印出来

这是我到目前为止所做的,但长度函数不起作用.

import string

def main():
    print " This program reads from a file and then prints out the"
    print " line with the longest length the line ,or with the highest sum"
    print " of ASCII values , or the line with the greatest number of words"
    infile = open("30075165.txt","r")
    for line in infile:
        print line
    infile.close()
def length():
    maxlength = 0
    infile = open("30075165.txt","r")
    for line in infile:
        linelength = lengthofline
        if linelength > maxlength:
            #If linelength is greater …
Run Code Online (Sandbox Code Playgroud)

python

2
推荐指数
2
解决办法
1万
查看次数

如何将字符串列表转换为数值?

如何将字符串列表(每个字符串表示一个数字,即[‘1’, ‘2’, ‘3’])转换为数值.

python

0
推荐指数
3
解决办法
452
查看次数

打印出具有最长长度的行,具有最高ASCII值总和的行或具有最大字数的行

我需要一些帮助来打印出具有最长长度的行,具有最高ASCII值总和的行,或者来自文本文件的具有最大字数的行.这是我第一次编程,我真的很挣python而且不​​知道如何计算本周需要我的实验室.我试图解决它,但到目前为止没有运气.谁能帮帮我吗?

python

-1
推荐指数
1
解决办法
248
查看次数

这个功能有什么作用?

def fun1(a,x):
    z = 0
    for i in range(len(a)):
        if a[i] == x:
            z = z + 1
    return z
Run Code Online (Sandbox Code Playgroud)

python

-3
推荐指数
1
解决办法
218
查看次数

这个功能有什么作用?

def fun1(a):

    for i in range(len(a)):
        a[i] = a[i] * a[i]
    return a
Run Code Online (Sandbox Code Playgroud)

python

-4
推荐指数
1
解决办法
236
查看次数

标签 统计

python ×5