Skip to content

Course home

Algorithms

Algorithms

EasyMediumHard
12345678910111213141516
Question 13

An international shipping company uses two-letter ISO country codes (e.g. "CA", "FR", "JP") to calculate shipping regions and delivery times. There are 249 valid country codes.

A program is required to verify if a user-entered shipping country code is valid and lookup its delivery time.

Each valid country code with its delivery time (in days) is stored as a record in a two-dimensional list, shippingTable. The records are stored sorted in alphabetical order by their country code.

Open file shipping_search.py

Write a program to meet these requirements:

Inputs

  • Prompt for and accept a two-letter country code from the user (AA to ZZ, inclusive).
    • Accept both uppercase and lowercase inputs.
    • No other validation of the user input is required.

Process

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

Outputs

  • When the country code is located, output the code and its delivery time.
  • When the expected alphabetical location is passed, output the next available country code alphabetical match in the list and its delivery time.
  • When the end of the list is reached without finding or passing the code, output the last country code in the list and its delivery time.

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 shipping_search_finished.py

[15]
Markscheme

Algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Algorithms

159 exam-style questions on Edexcel GCSE Computer Science Algorithms, covering Constructs for solving problems, Variables, constants and data structures, Arithmetic, relational and logical operators, Tracing algorithm output with trace tables, Types of error and correcting logic errors, Standard algorithms (sorts and searches), and Evaluating algorithm fitness and efficiency. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank