python3 realizes the function of mask drawing

1. The logic of mask lottery##

Each person generates a corresponding lottery code;
Begin drawing lots;
Announce the winning result;
The writing of this case is relatively simple. The actual production environment is much more complicated than this. However, the basic logic is still the same...

Second, the code of mask lottery##

import random

def get_random_code(num_code):"""
 Generate and return a random verification code
 : param num_code:Random verification code digits
 """
 list_code =[]for i inrange(num_code):
 # (1) Randomly generate three kinds of characters
 # (1-1) Randomly generate 0~Number 9
 num =str(random.randint(0,9))
 # (1-2) Randomly generate lowercase letters
 lower_alphabet =chr(random.randint(97,122))
 # (1-3) Randomly generate uppercase letters
 upper_alphabet =chr(random.randint(65,90))
 # (2) Randomly sample a character again
 random_code = random.choice([num, lower_alphabet, upper_alphabet])
 # (3) Save randomly selected characters
 list_code.append(random_code)return"".join(list_code)

def main():
 # Total number of draws
 draw_num =30
 # Total number of winners
 draw_result_num =10
 # List of total lottery codes
 draw_list =[]
 # List of winning lottery codes
 draw_result_list =[]

 # (1) Simulate to generate the lottery code. Actually, everyone should get the lottery code by themselves. Now use the loop to simulate
 for i inrange(draw_num):
 draw_code =get_random_code(6)while draw_code in draw_list:
 # Repeat label, need to regenerate lottery code
 draw_code =get_random_code(6)else:
 # Add the generated tag code to the list
 draw_list.append(draw_code)

 # (2) Simulate the process of drawing lots
 print("Produced a total of{}Lottery codes:{}".format(draw_num, draw_list))for i inrange(draw_result_num):
 # NO1:In this way, a total of the generated lottery codes will be deleted, so other methods are still used
 # random_index = random.randint(0,len(draw_list)-1)
 # draw_result_list.append(draw_list.pop(random_index))
 # NO2:
 a =0
 b =len(draw_list)-1
 draw_code = draw_list[random.randint(a, b)]while draw_code in draw_result_list:
 # Duplicate labels and draw lots
 draw_code = draw_list[random.randint(a, b)]else:
 # Add the lottery code to the list
 draw_result_list.append(draw_code)

 # (3) Announce the lottery results
 print("{}The lottery codes for the winning lottery are as follows:".format(draw_result_num))for item in draw_result_list:print(item)if __name__ =='__main__':main()

The console output:

A total of 30 lottery codes were generated: ['511uCZ','nAYBf8', '6I92sq', '206FxX', '1WMHCb','sdJUMU','e4A85p', '14Ae35','n4xA44', '94i4eG', ' L8981K', '11wtyN','i5k5Xk', '7S8Tf7','cGC4Ku','f8dM40','nBi958','ELDVqz','MQZFJQ','hPPqh5','Qr682E','E2Z4X4J','Ilm ,'J71Pc1','JPZpv8','svAlm3', '9GaS9U','v8378K', '116u2b','x688xP']

10 The lottery codes for the winning lottery are as follows:

i5k5Xk
v8378K
e4A85p
J71Pc1
hPPqh5
1 WMHCb
JPZpv8
sdJUMU
9 GaS9U
MQZFJQ

So far, this article about the function of python3 to implement mask lottery is introduced. For more related python3 mask lottery content, please search for previous articles on ZaLou.Cn or continue to browse related articles below. Hope you will support ZaLou.Cn more in the future!

Recommended Posts

python3 realizes the function of mask drawing
What is the id function of python
What is the function body of python
What is the function of adb in python
Python realizes the development of student management system
Consolidate the foundation of Python(7)
Python realizes online translation function
Detailed explanation of the principle of Python function parameter classification
Consolidate the foundation of Python(6)
Python realizes the guessing game
matplotlib of python drawing module
Consolidate the foundation of Python (3)
The usage of wheel in python
How Python implements the mail function
Python handles the 4 wheels of Chinese
Python simulation of the landlord deal
What is the use of Python
The premise of Python string pooling
Secrets of the new features of Python 3.8
Python realizes udp transmission picture function
How Python implements the timer function
The father of Python joins Microsoft
The operation of python access hdfs
The usage of tuples in python
Free definition of python drawing legend
End the method of running python
Understanding the meaning of rb in python
Can Python implement the structure of the stack?
What are the required parameters of python
Logistic regression at the bottom of python
The usage of Ajax in Python3 crawler
Python solves the Tower of Hanoi game
Solve the conflict of multiple versions of python
What is the scope of python variables
Python implements the sum of fractional sequences
Python realizes batch modification of file names
Two days of learning the basics of Python
Where is the pip path of python3
What are the advantages of python language
The specific method of python instantiation object
What is the prospect of python development
Python realizes the greedy snake double battle
The specific method of python import library
Solve the conflict of multiple versions of python
Detailed explanation of the principle of Python super() method
How to use the round function in python
Python realizes horizontal and vertical splicing of pictures
The difference between the syntax of java and python
How to use the zip function in Python
7 features of Python3.9
python drawing | IPCC-AR6 latest climate zone mask example
Python implements the shuffling of the cards in Doudizhu
The meaning and usage of lists in python
How to use the format function in python
Can the value of the python dictionary be modified?
Python implements the source code of the snake game
Detailed explanation of the usage of Python decimal module
How about learning python at the age of 27?
Python enumerate() function
The consequences of uninstalling python in ubuntu, very
Python implementation of hand drawing effect example sharing