这是我到目前为止所做的,但长度函数不起作用.
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) 我需要一些帮助来打印出具有最长长度的行,具有最高ASCII值总和的行,或者来自文本文件的具有最大字数的行.这是我第一次编程,我真的很挣python而且不知道如何计算本周需要我的实验室.我试图解决它,但到目前为止没有运气.谁能帮帮我吗?
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) def fun1(a):
for i in range(len(a)):
a[i] = a[i] * a[i]
return a
Run Code Online (Sandbox Code Playgroud) python ×5