Moovit data pipelines receive user IDs as strings. Validate whether an ID follows the required format and contains a correct checksum.
A valid ID must have the exact structure MVT-MARKET-BODY-CHECK, where:
MVT is the literal prefix.MARKET contains 2 to 4 uppercase ASCII letters.BODY contains 6 to 12 ASCII digits.CHECK contains exactly one ASCII digit.BODY. To calculate it, scan BODY from right to left, double digits at positions 0, 2, 4, and so on, subtract 9 when a doubled value exceeds 9, then choose the digit that makes the total divisible by 10.Implement is_valid_user_id(user_id) and return True only when every rule is satisfied. Return False for malformed input, incorrect casing, invalid characters, or an incorrect checksum.
def is_valid_user_id(user_id):