Topic 13: Question 2: Create a function that appends the name and email to the end of a named file.
This is the code I wrote:
def addEmail(filename, name, email):
f = open('filename', 'a')
f.write("%s\n" % name)
f.write("%s\n" % email)
f.close()
return f
This is the output that I get on pyschools website:
Test Cases Expected Result Returned Result Result
addEmail('email.txt', 'john', 'john@gmail.com').closed True True
Private Test Cases Passed Failed
What am I doing wrong?
Take a closer look at the sample output:
Note that in that output, the name and email are on the same line, separated by a space. You are putting the name and email on separate lines. Try changing your code to the following: