14
0/15

A program is being developed to generate a unique laboratory Asset Tracking Key (ATK).

The letter part of the registration key is made up of the first letter of the building name joined with the first three letters of the equipment's category. All letters must be in uppercase.

The number part of the registration key is the sum of the ASCII values for each digit in the 5-digit equipment asset number.

The registration key for equipment in building Lab Alpha with category Centrifuge and asset number 72019 is LCEN259, all in uppercase.

Original Python Code:

# Global variables
building = ""
category = ""
asset_num = ""

def generate_atk(building, category, asset_num):
    letter_part = building[0] + category[0:3]
    total = 0
    for char in asset_num:
        total = total + int(char)
    return letter_part + str(total)

# Main program
building = input("Enter building name: ")
category = input("Enter equipment category: ")
asset_num = input("Enter 5-digit asset number: ")

atk_code = generate_atk(building, category, asset_num)
print("Asset Tracking Key:", atk_code)

Task:

Amend the code to:

  • Ensure local and global variables with the same names are not confused:
    • Change the names of the local variables inside the generate_atk function to distinguish them from the global variables with the same names.
  • Display a system header:
    • Add a procedure called system_header, with no parameters, to display a message welcoming the user to the asset tracking system.
    • Call the system_header procedure before asking for any user input.
  • Ensure the building and category are all uppercase:
    • Convert the building name and category to uppercase after they are entered by the user.
  • Validate the asset number in the main program using code or built-in string methods:
    • Check that only character digits '0' to '9' appear in the asset number.
    • Call the generate_atk() function only if the asset number is valid.
    • Print an error message if the asset number is invalid. Invalid input must not be processed.
  • Generate the correct number part of the key in the function:
    • Correct the logic error caused by using the int() function in the number part calculation rather than using a function that returns the ASCII value of the character.

Do not add any additional functionality.

[15]

Develop code Questions

Practise Edexcel GCSE Computer Science Develop code with exam-style questions for GCSE Computer Science. 57 questions covering Decomposition and abstraction to solve problems, Read, write, analyse and refine programs, Converting algorithms into programs, Techniques for readable, maintainable code, Identifying and correcting program errors, and Evaluating program fitness and efficiency, matched to the Edexcel GCSE Computer Science (1CP2) specification and written in Paper 1 and Paper 2 style. Every question includes a full worked solution and mark scheme, so you can see where marks are awarded rather than just whether you got the answer right.

PreviousNext

Develop code Questions

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