reading file | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
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

13th Feb 2022, 1:27 AM
Knowledge Is Power
Knowledge Is Power - avatar
3 Respuestas
+ 1
Show your attempt. This is a fairly simple question
13th Feb 2022, 3:07 AM
Rishi
Rishi - avatar
+ 1
file = open("books.txt", "r") file.write("Harry Potter\n," "Parvana\n") for i in file.readlines(): print (i) file.close()
13th Feb 2022, 7:50 PM
Knowledge Is Power
Knowledge Is Power - avatar
+ 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)))
15th Feb 2022, 4:12 PM
Jerty