Python 文件处理。检测与英国系统不匹配的车牌

Python File handling. Detecting license plates that don't match the british system

我的任务是创建一个 Python 程序来识别与英国注册系统不匹配的车牌。

在英国,大多数车辆登记采用以下格式:

• Two letters

• Two numbers

• Three letters.

例如,AZ01 XYZ

与该系统不匹配的车牌将被写入 .txt 文件,并同时记录其平均速度。

我是 Python 的新手,几乎没有编码经验,到目前为止没有任何东西可以展示。

首先检查每组字符是字母(字母)还是数字(数字), 如果不是有效的车牌,请将其附加到文件中。

licence_plate = 'AZ01 XYZ'

if not (licence_plate[:2].isalpha() 
        and licence_plate[2:4].isdigit() 
        and licence_plate[5:].isalpha()):
            fo = open("ishouldstudymore.txt", "aw")
            fo.write(licence_plate)
            fo.close()

您必须阅读以下链接才能理解上面的内容。

isDigit

isAlpha

Python Strings

Python File IO

Python Loops