gpt4 book ai didi

python - 如何解决 'Private Test Cases' PySchool

转载 作者:行者123 更新时间:2023-12-03 08:43:23 24 4
gpt4 key购买 nike

我真的很困惑。
我正在解决大学的PySchool实践,并在主题13:问题2上遇到了问题。
我需要:
创建一个将名称和电子邮件附加到命名文件末尾的函数。

我使用的代码:

    # Create a function that appends the name and email to the end of a named file.
def addEmail(filename, name, email):
f = open(filename, 'a') # replace the mode
f.write("\n"+name+' '+email)
# Append name and email, each record should end with '\n'.
f.close()
# close file
return f # do not remove this line

我得到:
Error
我不明白我的错误在哪里。请帮忙。

最佳答案

您的代码在添加到文件的行的开头放置了换行符。但是,很可能该文件在开始的最后一行末尾已经有换行符。

而是应将换行符放在添加的行的末尾。我已经尝试过这种变化;有用。

关于python - 如何解决 'Private Test Cases' PySchool,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59651511/

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