Python生成随机生成车牌号代码
时间: 2023-05-23 13:05:03 浏览: 169
Python实现随机生成任意数量车牌号
import random
# 定义生成车牌号的函数
def generate_plate_number():
province = ["京", "津", "沪", "渝", "冀", "豫", "云", "辽", "黑", "湘",
"皖", "鲁", "新", "苏", "浙", "赣", "鄂", "桂", "甘", "晋",
"蒙", "陕", "吉", "闽", "贵", "粤", "青", "藏", "川", "宁",
"琼"]
city = ["A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M",
"N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
number = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
# 随机生成车牌前两位(省份+字母)
plate = random.choice(province) + random.choice(city)
# 随机生成车牌后五位(数字+字母)
for i in range(5):
plate += random.choice(number + city)
return plate
# 打印生成的车牌号
print(generate_plate_number())
阅读全文