我尝试正确使用 map 并使用 if 语句来确保列表是否为空以不继续和停止。我也会显示输入。为了澄清起见, numbers_1 函数是我使用 map 选项的地方。我需要编辑什么才能完成这项工作?我对如何解决这个问题感到困惑我的代码如下是我的代码
#this is the input file
#John Jackson
#91 94 38 48 70 85 94 59
#James Johnson
#78 96 90 55 77 82 94 60
#Edward Kinsley
#99 94 82 77 75 89 94 93
#Mozilla Firefox
#49 92 75 48 80 95 99 98
def lab8():
userinput= "Lab8.txt"
lenoffile= len(userinput)
print "There is", lenoffile, "lines"
File= open (userinput, "r")
studentscores1= File.read()
studentlist= studentscores1.split("\n")
return studentlist, lenoffile
def Names_1(studentlist, lenoffile):
print "=============================="
ai = ""
for i in range (0, lenoffile, 2):
ai += studentlist[i] + "\n"
print "===============below is ai=========="
print ai
return ai
def Numbers_1(studentlist, lenoffile):
bi= ""
for i in range (1, lenoffile, 2):
bi += studentlist[i] + "\n"
bi = bi.split ("\n")
print bi
return bi
print "====================BELOW IS THE SCORE========================="
def Outputfile_1(ai):
outputfile= raw_input ("What is the output file.txt:")
File2= open(outputfile, "w")
File2.write(ai)
return outputfile
def numbers_1(bi):
for b1 in bi:
b1 = b1.split(" ")
lenofb1 = len(b1)
quiztotalb = 0
midtermb = 0
Final = 0
if lenofb1 > 0:
b1 = map(int, b1)
quiztotal = ((b1[0] + b1[1] + b1[2] + b1[3] + b1[4])/5)
midtermtotal = ((b1[5]) + b1[6])/2
Finaltotal = (b1[7])
Score = (quiztotal*.3 + midtermtotal*.4 + Finaltotal*.3)
print Score
def main():
studentlist, lenoffile = lab8()
ai = Names_1(studentlist, lenoffile)
bi = Numbers_1(studentlist, lenoffile)
#outputfile = Outputfile_1(ai)
numbers_1(bi)
main()
从这里我明白了ValueError: invalid literal for int() with base 10: ''
我一直在努力,我不确定我应该从这里去哪里。