Computer Science, asked by thecoder19, 3 months ago

You have been asked to make a special book categorization program, which assigns each book a special code based on its title.

The code is equal to the first letter of the book, followed by the number of characters in the title.

For example, for the book "Harry Potter", the code would be: H12, as it contains 12 characters (including the space).



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.



For example, if the books.txt file contains:

Some book

Another book



Your program should output:

S9

A12​

Answers

Answered by girishsharma192012
1

Answer:

You have been asked to make a special book categorization program, which assigns each book a special code based on its title.

The code is equal to the first letter of the book, followed by the number of characters in the title.

For example, for the book "Harry Potter", the code would be: H12, as it contains 12 characters (including the space).

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.

For example, if the books.txt file contains:

Some book

Another book

Your program should output:

S9

A12

Answered by jai696
4

\huge\red{\mid{\fbox{\tt{Using\: Python\: 3}}\mid}}

code_gen = lambda name: name[0] + str(len(name))

with open("code.txt") as f:

lines = f.readlines()

names = [line.strip() for line in lines]

codes = list(map(code_gen, names))

print("\n".join(codes))

\large\mathsf\color{lightgreen}useful?\: \color{white}\longrightarrow\: \color{orange}brainliest!

Similar questions