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

时间:2015-03-17 11:31:52

标签: python regex file-handling

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

在英国,大多数车辆注册的格式为:

  

•两个字母

     

•两个数字

     

•三个字母。

例如,AZ01 XYZ

与此系统不匹配的印版将写入.txt文件,并将其平均速度记录在旁边。

我是Python的新手,几乎没有经验编码,到目前为止没有任何表现。

1 个答案:

答案 0 :(得分:-1)

首先检查每组字符是否是字母(字母)或数字(数字), 如果没有,有效的牌照会将其附加到档案中。

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

相关问题