+ 4

I'm solving the new test on python and im stuck at book title

Im getting the same expectied result as an output but it still tells me failed task what's wrong???

13th Oct 2020, 1:07 AM
Mustafa Thaer
Mustafa Thaer - avatar
37 Answers
+ 2
https://code.sololearn.com/c5LfMwEmIx2v/?ref=app compare your code with this one👆🏻
13th Oct 2020, 9:49 AM
Ren
+ 13
file = open("/usercode/files/books.txt","r").readlines() for line in file: line = line.rstrip("\n") print(line[0] + str(len(line)))
28th Oct 2020, 8:08 AM
Taral Patel
Taral Patel - avatar
+ 9
A simpler way with 5 lines of code. A simple explanation, loop through all lines, and if a line has trailing/ending "\n" remove it from the count of the length. https://code.sololearn.com/cdaPdMWWeN3W/?ref=app
15th Dec 2020, 6:45 PM
Lam Wei Li
Lam Wei Li - avatar
+ 5
Mustafa Thaer , you have to keep in mind that there’s a special condition for the last book of the list, which is that it has no newline “/n” character unlike the rest of the books. So you have to take that into account, every single book will have an extra countable character (newline or “/n”) except for the last one. My suggestion to you is to insert an if/else statement to address that. Good luck!
14th Oct 2020, 4:59 AM
fch0
+ 2
Simba its only 6 lines 2 of them are given for open and close file the code runs and my result and the expectid result are the exact same .. is it ok to show you my answer?? this is my solution file = open("/usercode/files/books.txt", "r") for line in file: nums= list(line) x=len(nums)-1 print(line[0]+str(x)) file.close()
13th Oct 2020, 1:30 AM
Mustafa Thaer
Mustafa Thaer - avatar
+ 2
Avalon text file contains a books names they want me to print the first letter of the name with how many characters it has "space included " with every line has \n need to exclude For exaple "Harry potter" = H12 and so on
13th Oct 2020, 2:50 AM
Mustafa Thaer
Mustafa Thaer - avatar
+ 2
Ren thank you , can you explain why it worked while my code did'nt? Im cunfused really
13th Oct 2020, 1:22 PM
Mustafa Thaer
Mustafa Thaer - avatar
+ 2
Hi, Mustafa Thaer. Did you manage to solve it? In the instructions, they mention something important: all the lines have this special character '\n' except the last. If only there was a way to count the length of a line without counting a specific character... 😁 Did you know it is possible to remove the white spaces of a string with a certain method? Maybe that works with other characters, too. I hope that helps.
14th Oct 2020, 11:38 AM
D.R.
D.R. - avatar
14th Oct 2020, 9:10 PM
JaScript
JaScript - avatar
+ 1
which task? there is no explanation what is given and task what you are trying to do
13th Oct 2020, 2:21 AM
Shadoff
Shadoff - avatar
+ 1
try this one: for line in file: print(line[0] + str(len(line)-2))
13th Oct 2020, 2:58 AM
Shadoff
Shadoff - avatar
+ 1
Avalon it worked but still not pass
13th Oct 2020, 3:04 AM
Mustafa Thaer
Mustafa Thaer - avatar
+ 1
Avalon i did some changes and keep geting the same result but did'nt pass 💔
13th Oct 2020, 3:05 AM
Mustafa Thaer
Mustafa Thaer - avatar
+ 1
Can you post a link to the task?
13th Oct 2020, 3:27 AM
Shadoff
Shadoff - avatar
+ 1
send me your code link and i’ll try to look for the error :)
13th Oct 2020, 3:06 PM
Ren
+ 1
Ren thank you i sent it to your DMs
13th Oct 2020, 3:13 PM
Mustafa Thaer
Mustafa Thaer - avatar
+ 1
fch0 at the first it was only 3 results showing i did'nt know that there is more under so i was confused cuz the problem was at last line thanks for you help i appreciate it
14th Oct 2020, 5:09 AM
Mustafa Thaer
Mustafa Thaer - avatar
+ 1
sorry, I’m not able to view my messages in sololearn(-.-;)
14th Oct 2020, 7:14 AM
Ren
+ 1
K. Bharath 😂😁😁😂😂👍 do you also need our bank account password?
14th Oct 2020, 2:31 PM
Shadoff
Shadoff - avatar
+ 1
Well you need to "strip" ☺. Sounds like you already have though
14th Oct 2020, 5:30 PM
Python Trader
Python Trader - avatar