0
Solution book titles
I don't able write code for this practice . Anyone help me
8 Respostas
+ 8
Thanks I solved it
file = open("/usercode/files/books.txt", "r")
for word in file.readlines():
if "\n" in word:
print (word[0]+str(len(word)-1))
else :
print (word[0]+str(len(word)))
file.close()
+ 1
with open("/usercode/files/books.txt", "r") as f:
for line in f:
line=line.rstrip()
print(line[0]+str(len(line)))
+ 1
file = open("/usercode/files/books.txt", "r")
#your code goes here
a=file.readlines()
for i in a:
b=i.replace("\n","")
print(i[0] + str(len(b)))
file. close()
Mine looks different, 😅 hope it will help u
0
Where's your attempted code?
Post them here
0
thank you very much
- 2
This would another way to solve it, if you don´t realise question "in" at if statement. First read lines to count them, after read them again making condition, controls end line respect first lines
file = open("/usercode/files/books.txt", "r")
#your code goes here
cont = 0
for i in file:
cont+=1
file.close()
lines = open("/usercode/files/books.txt", "r")
i = 0
for j in lines:
i+=1
if i != cont:
print( j[0] + str(len( j ) - 1 ))
else:
print( j[0] + str(len( j )))
lines.close()