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
12 Réponses
+ 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)
+ 2
Post your code here
+ 2
file = open("/usercode/files/books.txt", "r")
#your code goes here
for line in file:
print(line[0],(len(line)-1))
file.close()
+ 2
visph For you to count chars excluding an eventual newline, I recommend rstrip:
n = len(line.rstrip())
+ 1
print(line[0] + (len(line)-1)) #commas add whiespace
+ 1
I tried this but it shows error
+ 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.
+ 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()
+ 1
Denise Roßberg doesn't remember too: just remember the task requirements ;)
+ 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 ^^
0
My output is like A 5
0
visph
I am still wondering which challenge it is.