CODINGAME: TABLE OF CONTENTS

Subscribers:
4,890
Published on ● Video Link: https://www.youtube.com/watch?v=IIzXKeYSPjQ



Duration: 11:31
18 views
1


You are writing a book, and the table of contents is the only thing left to do. Sadly, the necessary packages are not working well, so you will have to implement one yourself.

EXPLANATION CODE:
1) First, the program takes input from the user for the length of the line and the number of titles. Then, it creates an empty list called titleList to store the titles and their page numbers.

2) Next, the program reads in each title and page number, splits them on the space character, and adds them as a sub-list to titleList.

3) After this, the program loops over each title in titleList. For each title, it generates a table of contents line based on the number of greater than characters in the title

4) The number of greater than characters in the title is counted using the count() method, and this number is stored in the counter variable. The titles list keeps track of how many titles have been seen at each level of indentation so that the table of contents can be generated correctly.

5) If there are counter greater than characters, the program sets the titles[counter] value to 0 to reset the count of titles at that level of indentation.

6) Next, the program increments the titles[counter] value to count the current title at that level of indentation.

7) After that, the program generates the table of contents line by adding counter times 4 spaces (to match the level of indentation), then the current titles[counter] value, the title text (with all greater than characters removed), enough dots to fill up the rest of the line to lengthofline, and finally the page number for the current title.

8) Finally, the program prints the completed table of contents line.

Contents:
0:00 - Reading
1:55 - Solving
9:31 - Explaining

#codingame #coding #game #programming #easy #difficulty #reading #arithmetic #python #pythonprogramming #learntocode #tutorial #education #problemsolving #algorithmic #asmr #asmrtyping #table #of #contents #strings #parsing







Tags:
codingame
coding
game
programming
problem solving
problem
solving
algorithmic
reading
asmr
asmr typing
education
easy difficulty
easy
difficulty
tutorial
how to program
explanation
how to
python
python programming
table of contents
table
of
contents
strings
parsing