Files and Functions Challenge Questions
Hello,
- How come there is no video @ the end of this section going over the solution to the 6 Questions in this sectio
- Regarding Question 4:
Q4:
1) Create a new file called "capitals.txt" ,
2) store the names of five capital cities in the file on the same line.
THis was # My Humble attempt:
#--------------------------------------------
f = open('capitals.txt','w') # Correct
f.write('Toronto, Montreal, Vancouver, Calgary, Winnipeg')
f.close()
f = open('capitals.txt','r')
print(f.read())
ACTUAL SOLUTION:
file = open('capitals.txt','w')
file.write('London, ')
file.write('Paris, ')
file.write('Madrid, ')
file.write('Lisbon, ')
file.write('Rome,')
file.close()
f = open('capitals.txt','r')
print(f.read())
My Question Q4: is my method of lumping the 5 capitals into one "f.write()" function a viable alternative...it print on one line :)
Regards,
Matt
1 answers ( 0 marked as helpful)
Hi Matt,
thanks for reaching out and sorry for the delayed response.
Your option seems in order. If you'd like you can share the results of your approach here in the hub.
Best,
365 Eli