Number plate

We represent a car registration as a string with four digits followed by a whitespace character and three consonant capital letters.

Save all functions into the same file named numberplate.py.

  1. Write the function pos_letter() that takes a number plate (string) and another string with one character, and returns the first position of this character within the three letters group of the number plate. If this character is different from all three letters then the function will return -1. Examples:

    >>> pos_letter('7732 CHW','A')
    -1
    >>> pos_letter('7216 ABS','S')
    2
    >>> pos_letter('8717 DBW','B')
    1
    

    Note

    More tests are provided in the test-numberplate1.txt file.

  2. Write the function only_digits() that takes a number plate (string), and returns True if the first four characters of the number plate are digits and False otherwise. Examples:

    >>> only_digits('7732 CHW')
    True
    >>> only_digits('7FG2 CHW')
    False
    >>> only_digits('7652 12W')
    True
    >>> only_digits('7652BCD')
    True
    

    Note

    More tests are provided in the test-numberplate2.txt file.

  3. Write function is_upper_consonant() that given a string with one character returns True if this character is a uppercase consonant letter and False otherwise. Examples:

    >>> is_upper_consonant('B')
    True
    >>> is_upper_consonant('H')
    True
    >>> is_upper_consonant('A')
    False
    >>> is_upper_consonant('b')
    False
    

    Note

    More tests are provided in the test-numberplate5.txt file.

  4. Write the function only_consonants() that takes a number plate (string), and returns True if the last three characters of the number plate are consonant capital letters and False otherwise. One way of designing this function is by using function is_upper_consonant(). Example:

    >>> only_consonants('7216 XBS')
    True
    >>> only_consonants('7TG4 TNT')
    True
    >>> only_consonants('7216 ABU')
    False
    >>> only_consonants('7216 TnT')
    False
    >>> only_consonants('7216 GH6')
    False
    >>> only_consonants('7652BCD')
    True
    
    

    Note

    More tests are provided in the test-numberplate3.txt file.

  5. Write the function correct_numberplate() that takes a number plate (string), and returns True if the number plate is correct (see definition at the beginning) and False otherwise. This function must call some of the previous functions.

    See the following examples:

    >>> correct_numberplate('7732 CHW')
    True
    >>> correct_numberplate('7FG2 CHW')
    False
    >>> correct_numberplate('7216 TBS')
    True
    >>> correct_numberplate('7216 BB3')
    False
    >>> correct_numberplate('7276 OEH')
    False
    >>> correct_numberplate('7276 tnt')
    False
    >>> correct_numberplate('7276BCD')
    False
    

    Note

    More tests are provided in the test-numberplate4.txt file.

Solutions

A solution of these functions is provided in the numberplate.py file.