""" Use this file to develop and test your Assignment 3 functions S0, 2020.""" def main(): print_header(7, "is_a_valid_code()") test_is_a_valid_code() #-------------------------------------------------- # 7777777777777777777777777777777777777777777777777 # Returns True if the parameter string is a # valid code, the function returns # False otherwise #-------------------------------------------------- """ Define the is_a_valid_code() function which is passed a string as a parameter. The function returns a boolean indicating whether the parameter string is a valid code or not. A valid code is a string made up of one letter followed by one or more digits (can also include spaces before, between or after the digits). The first three lines of code inside the function should be: code_letters = ["S", "B", "N", "T", "P"] min_for_each_letter = [1, 3, 4, 0, 3] #inclusive max_for_each_letter = [7, 9, 6, 7, 5] #inclusive where: • code_letters is the list of code letters which are valid for the first letter of the code string, • min_for_each_letter is a list which contains the minimum possible number (inclusive) for each digit following that letter, • max_for_each_letter is a list which contains the maximum possible number (inclusive) for each digit following that letter. For example, the third element of the code_letters list is the letter 'N', the corresponding third element of the min_for_each_letter list is 4 and the corresponding third element of the max_for_each_letter list is 6. This indicates that the code digits which follows the letter 'N' can be any number made up of the digits 4, 5 or 6. The number part of a valid code string can also contain any number of spaces. Note: The number part of a parameter code string to be tested could contain an alphabetic character thus making the code not valid. You will find it useful to use the string method, isdigit(), which returns True if a string is a digit, False otherwise. For example, the following code: print("1.", is_a_valid_code('B747346')) print("2.", is_a_valid_code('N 444 454')) print("3.", is_a_valid_code('T 400 4854')) print("4.", is_a_valid_code('S 444S454')) print("5.", is_a_valid_code('P ')) print("6.", is_a_valid_code('T 0 ')) prints: 1. True 2. True 3. False 4. False 5. False 6. True """ def is_a_valid_code(code_string): code_letters = ["S", "B", "N", "T", "P"] min_for_each_letter = [1, 3, 4, 0, 3] #inclusive max_for_each_letter = [7, 9, 6, 7, 5] #inclusive def test_is_a_valid_code(): print("1.", is_a_valid_code('B747346')) print("2.", is_a_valid_code('N 444 454')) print("3.", is_a_valid_code('T 400 4854')) print("4.", is_a_valid_code('S 444S454')) print("5.", is_a_valid_code('P ')) print("6.", is_a_valid_code('T 0 ')) codes_to_check = ['B45 5', "P-534", 'S5 45 4 4 54', 'B3 9S56 8 '] number = 7 for code in codes_to_check: print(str(number) + ". ", code, ": ", is_a_valid_code(code), sep = "") number = number + 1 print() #-------------------------------------------------- # Print header lines #-------------------------------------------------- def print_header(number, text): text = str(number) + ". " + text print("-" * 30) print(str(number) * 30) print(text) print("-" * 30) main()