Skip to content
MathsGenie logo
Open app

Course home

  1. IGCSE
  2. Computer Science Edexcel
  3. Question bank

Develop code

EasyMediumHard
123456789101112
Question 7

A streaming music platform needs to compile and index its standard list of music genres.

The file Genres.txt contains a list of ten master genres.

Write a program to implement these requirements.

For all lines in the Genres.txt file, the code must:

  • Read the line.
  • Append a sequential line number (starting at 1) and a space to the front of the genre name.
  • Write the newly formatted line to a file named Indexed.txt.
  • Print the output line to the display.

You should structure your program cleanly by opening and closing files correctly.

File Formats

Genres.txtIndexed.txt
Rock1 Rock
Pop2 Pop
Jazz3 Jazz
Classical4 Classical
Hip Hop5 Hip Hop
Electronic6 Electronic
Reggae7 Reggae
Blues8 Blues
Folk9 Folk
Country10 Country
[7]

Develop code Questions

  1. IGCSE
  2. /Computer Science
  3. /Develop code