6Hard
0/15

An astronomical observatory monitors asteroids using unique three-letter designations (e.g. "APO", "BEN", "CER") to track their minimum orbital intersection distances.

A Python program is required to verify if a user-entered asteroid designation is registered and lookup its orbital distance.

Each registered asteroid and its orbital distance (in Astronomical Units, AU) is stored as a record in a two-dimensional list, asteroidTable. The records are stored sorted in alphabetical order by their asteroid designation.

Open file asteroid_search.py

Write a program to meet these requirements:

Inputs

  • Prompt for and accept a three-letter asteroid designation from the user (AAA to ZZZ, inclusive).
    • Accept both uppercase and lowercase inputs.
    • No other validation of the user input is required.

Process

  • Create a linear search to locate the asteroid designation in asteroidTable.
    • Stop the search as soon as:
      • The designation is located.
      • The expected alphabetical location of the user's designation is passed.
      • The end of the list is reached after all records have been checked.
    • Ensure the search works correctly for an asteroidTable of any length.

Outputs

  • When the designation is located, output the designation and its orbital distance.
  • When the expected alphabetical location is passed, output the next available asteroid designation alphabetical match in the list and its orbital distance.
  • When the end of the list is reached without finding or passing the designation, output the last asteroid designation in the list and its orbital distance.

Use comments, white space and layout to make the program easier to read and understand.

Do not add any additional functionality.

Save your amended code as asteroid_search_finished.py

[15]
PreviousNext

Computational thinking Questions

  1. GCSE
  2. /Computer Science
  3. /Computational thinking