0

How to print first letter of title and length of title except first. And output must stick together...

Suppose title is Amazon so output must A5

10th Jun 2021, 3:49 PM
akshay atugade
12 ответов
+ 4
akshay atugade Because of the comma in the print statement. You need to convert len into string using str() line[0] + str(len(line)-1)
10th Jun 2021, 4:00 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Post your code here
10th Jun 2021, 3:53 PM
Atul [Inactive]
+ 2
file = open("/usercode/files/books.txt", "r") #your code goes here for line in file: print(line[0],(len(line)-1)) file.close()
10th Jun 2021, 3:54 PM
akshay atugade
+ 2
visph For you to count chars excluding an eventual newline, I recommend rstrip: n = len(line.rstrip())
12th Jun 2021, 1:11 AM
Emerson Prado
Emerson Prado - avatar
+ 1
print(line[0] + (len(line)-1)) #commas add whiespace
10th Jun 2021, 3:59 PM
Steven M
Steven M - avatar
+ 1
I tried this but it shows error
10th Jun 2021, 4:00 PM
akshay atugade
+ 1
akshay atugade Which error? Unfortunately I can't find the challenge but I am sure that I solved it this way. Would be fine if you can share the challenge link.
10th Jun 2021, 4:05 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
akshay atugade each lines ends with a new line char except the last one, and you are requested to output first letter followed by full title length (excluding the last new line char)... file = open("/usercode/files/books.txt", "r") for line in file: n = len(line)-str(line[-1]=="\n") print(line[0]+str(n)) file.close()
10th Jun 2021, 6:01 PM
visph
visph - avatar
+ 1
Denise Roßberg doesn't remember too: just remember the task requirements ;)
10th Jun 2021, 6:18 PM
visph
visph - avatar
+ 1
Emerson Prado there are a lot of ways to reach the same result: here I used what seems to be known by OP, not what I would have do ^^
12th Jun 2021, 1:13 AM
visph
visph - avatar
0
My output is like A 5
10th Jun 2021, 3:55 PM
akshay atugade
0
visph I am still wondering which challenge it is.
10th Jun 2021, 6:16 PM
Denise Roßberg
Denise Roßberg - avatar