Finish this Code!
We want to open a file called "names.txt" and display all of the lines of the file as a list.
When you are finished, the output should match Desired Output.
Notice: due to limitations with readine files in an online environment, the line breaks will display as \\\\n. Do not be alarmed!
# Open the File
fin =
# Use readlines to store
# the file in a list
# Use indexing to
# display the 3rd line
# Close the file
fin.close()
Desired output is
Ron Weasley
Source Code:
Output:
Code in text format (See above image of code for indentation):
# Open the File
fin =open("names.txt",'r')
# Use readlines to store
# the file in a list
file=[name for name in fin.readlines()]
# Use indexing to
# display the 3rd line
print(file[2])
# Close the file
fin.close()
names.txt file: (This file and source code file must be in same location)
John Warn
Smith Soley
Ron Weasly
Tim Lee
Bruce Lee
Berners Lee
Canady Joseph
Joseph Canady
Get Answers For Free
Most questions answered within 1 hours.