0
reading file
You are provided a books.txt file, which includes the book titles, each one written on a separate line. Read the title one by one and output the code for each book on a separate line.file = open("books.txt", "r") file = ["Harry Potter\n", "Parvana Journey\n"] print(file.readlines()) file.close() Output: H12 P15
3 odpowiedzi
+ 1
Show your attempt. This is a fairly simple question
+ 1
file = open("books.txt", "r")
file.write("Harry Potter\n," "Parvana\n")
for i in file.readlines():
print (i)
file.close()
+ 1
with open('file.txt', 'w') as f:
f.writelines(['Harry Potter\n','Parvana Journey\n'])
with open('file.txt','r') as f:
n=f.readlines()
for i in n:
new_str=i.strip()
print('{}{}'.format(new_str[0],len(new_str)))