A program is being developed to generate a unique staff registration code.
The letter part of the registration code is made up of the first letter of the department joined with the first three letters of the employee's surname. All letters must be in uppercase.
The number part of the registration code is the sum of the ASCII values for each digit in the 6-digit staff code.
The registration code for an employee in Sales with surname Taylor and staff code 840131 is STAY305, all in uppercase.
# Global variables
department = ""
surname = ""
staff_code = ""
def make_reg_code(department, surname, staff_code):
letter_part = department[0] + surname[0:3]
total = 0
for char in staff_code:
total = total + int(char)
return letter_part + str(total)
# Main program
department = input("Enter department: ")
surname = input("Enter surname: ")
staff_code = input("Enter 6-digit staff code: ")
reg_code = make_reg_code(department, surname, staff_code)
print("Registration Code:", reg_code)
Amend the code to:
make_reg_code function to distinguish them from the global variables with the same names.welcome_message, with no parameters, to display a message welcoming the user to the registration system.welcome_message procedure before asking for any user input.make_reg_code() function only if the staff code is valid.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.
FINAL ANSWER:
# Global variables
department = ""
surname = ""
staff_code = ""
def welcome_message():
print("Welcome to the Registration System")
def make_reg_code(p_dept, p_surname, p_code):
letter_part = p_dept[0] + p_surname[0:3]
total = 0
for char in p_code:
total = total + ord(char)
return letter_part + str(total)
# Main program
welcome_message()
department = input("Enter department: ").upper()
surname = input("Enter surname: ").upper()
staff_code = input("Enter 6-digit staff code: ")
if staff_code.isdigit():
reg_code = make_reg_code(department, surname, staff_code)
print("Registration Code:", reg_code)
else:
print("Invalid staff code. Only digits are allowed.")
51 exam-style questions on Edexcel GCSE Computer Science Develop code, 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. Each one has a worked solution and a mark scheme showing where the marks go.