def convert(score):
if score >= '90':
msg = "Congratulations! You earned an A!"
(msg)
elif score >= '80':
msg = "You earned a B; good job!"
(msg)
elif score >= '70':
msg = "You earned a C; looks like you need to study a little harder."
(msg)
elif score >= '60':
msg = "You earned a D; maybe you should consider tutoring"
(msg)
else:
score < '60'
msg = "I'm sorry; you failed."
(msg)
return convert
def main():
infilename = input("Please enter the name of the input file: ")
outfilename = input("Please enter the name of the output file: ")
infile = open(infilename,"r")
outfile = open(outfilename,"w")
for line in infile:
msg = convert(line)
print(msg,file=outfile)
infile.close()
outfile.close()
main()
成绩本应打印到文件中,但当我打开文件时,它只显示:<function convert at 0x02DE8C00> .如果我运行代码,并且不尝试将它打印到文件中,它会工作正常。
好吧,他们想让我添加更多细节,但我真的想不出还有什么要添加的,我想你明白了。
这次我做错了什么?
请您参考如下方法:
您的函数返回自身 (return convert) 而不是 msg。
