Skip to content

Course home

Algorithms

Algorithms

EasyMediumHard
12345678910111213141516
Question 14

A program is needed for a library check-in system to validate members using a unique Membership Code and a four-digit PIN.

The member records are stored in a two-dimensional list. Each record contains: Member ID, Last Name, First Name, Membership Code, and PIN.

The list is sorted alphabetically by Membership Code. All members have PINs that are integers between 1000 and 9999 inclusive.

Open file Q06.

Write a program to meet the following requirements:

Inputs

  • Prompt for and accept a Membership Code (no input validation required).
  • Prompt for and accept a four-digit PIN. You can assume only configuration-valid integers will be entered.
  • Validate the PIN to ensure it is between 1000 and 9999, inclusive. The user must be re-prompted until a valid PIN is entered.

Process

  • The program must work with any number of records in the two-dimensional list.
  • Use a linear search to find the record matching both the entered Membership Code and PIN.
  • Stop searching early when the alphabetical position where the Membership Code should have been found is exceeded. For example, if searching for 'BRON5' and the search reaches 'CRUX1', the program should stop searching as 'BRON5' cannot appear later in the sorted list.
  • The program does not need to run in a continuous loop after the check is complete.

Outputs

  • If the correct Membership Code and matching PIN are found, display a personalized welcome message including the member's first name and last name.
  • If they are not found, display an "Access Denied - Invalid Credentials" message.

Do not add any additional functionality.

Use comments, white space and indentation to make your program readable and easy to follow.

Save your amended code as Q06FINISHED.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