python编写随机抽取京牌

2021/11/28 1:11:56

本文主要是介绍python编写随机抽取京牌,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!


# -*- coding:utf-8 -*-
# __author__ = "林深见鹿海蓝见鲸"
# ③随机20个京牌
import string
import random

car_list = []
begin = "京"
count = 0
while count<3:
    # count+=1
    for i in range(20):
        # print(i)
        one_number = random.choice(string.ascii_uppercase)
        # print(one_number)
        s = string.ascii_uppercase + string.digits
        c = random.sample(s,5)
        last_number = ''.join(c)
        # print(last_number)

        result = begin + one_number + last_number
        # print(result)
        car_list.append(result)
    print(f"随机20个车牌号{car_list}")
    choice = input("请输入你喜欢的车牌:")
    if choice in car_list:
        print("恭喜你选的车牌为:",choice)
        exit()
    else:
        print("车牌号不在范围内")
        print(f"还剩{2-count}次机会")
    count += 1

 



这篇关于python编写随机抽取京牌的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程