Skip to content

Course home

Develop code

Develop code

EasyMediumHard
123456789101112
Question 11

A program stores pairs of musical instruments in a two-dimensional array.

Each instrument name in a pair starts with a different letter.

Each pair should be stored in alphabetical order, but some are not.

The final pair in the list is always empty, representing placeholders.

The program must:

  1. Find and replace the final empty pair of instruments with the string values in the variables instrument1 and instrument2.
  2. Display the pair number (starting at 1), followed by space, then the two instruments in the pair, without any punctuation.
  3. Identify and display the longer instrument name in the pair, indented by four spaces.
  4. Check if the pair is currently in alphabetical order. If it is not in alphabetical order, display the pair sorted in alphabetical order, indented by four spaces, without any punctuation.

Starter Code

instrument_pairs = [
    ["Harp", "Oboe"],
    ["Guitar", "Banjo"],
    ["Tuba", "Saxophone"],
    ["", ""]
]

instrument1 = "Drums"
instrument2 = "Keyboard"

Intended Output

1 Harp Oboe
    Oboe
2 Guitar Banjo
    Guitar
    Banjo Guitar
3 Tuba Saxophone
    Saxophone
    Saxophone Tuba
4 Drums Keyboard
    Keyboard

Write a program to produce the intended output. Your program should function correctly even if the number of pairs in the array is changed. Save your code as Q06FINISHED.

[20]
Markscheme

Develop code Questions

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

62 exam-style questions on Edexcel IGCSE Computer Science Develop code. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank