Skip to content

Course home

Develop code

Develop code

EasyMediumHard
1234567891011121314151617181920212223242526
Question 22

Marcus runs a local courier business and wants to write a software tool to audit the formatting of tracking codes stored in a text document.

The text file tracking_codes.txt contains one tracking code on each line.

He wants a program to check each tracking code to ensure that:

  • the first character is a lowercase letter
  • if the first character is a lowercase letter, the code must also contain at least one digit (0–9)

If a tracking code does not meet these requirements, the program must:

  • display the invalid tracking code
  • increment a counter tracking the number of non-compliant codes

After all tracking codes in the file have been checked, the program must display the total count of non-compliant codes.

Write an algorithm, in Python or pseudocode, to solve Marcus's problem. You can use the incomplete program structure provided below to help you write your solution.

# Open the file
file = open("tracking_codes.txt", "r")
invalid_count = 0

# Loop through each line in the file
for line in file:
    code = line.strip()
    # Write your validation logic below

# Close the file and display the final count
file.close()
[9]
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