Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to develop Mini Program in annual lottery

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to develop Mini Program in the annual lottery". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Annual draw Mini Program, using object-oriented to achieve, design a lottery class, the class contains an attribute (number source), a method: generate all raffle levels of the specified number of lucky draw numbers.

The following knowledge points are used:

1. Partial function usage of csv module

2. Sys module reads input

3. Random module function choice function usage

4. Addition and deletion of list and dictionary elements

6. Range usage in for loop

7. Class and object-oriented

8. Character printing, calculation in print

With in 9.open

#! / usr/bin/python

# coding=utf-8

Import csv

Import sys

Import random

Reload (sys)

Sys.setdefaultencoding ('utf8')

# coding=utf-8

Print ("start raffle")

# define a raffle class with the function of inputting the raffle level and number, and printing out the raffle employee number for each level

Class Choujiang:

# define scv file path

Def _ init__ (self,filepath):

Self.empfile = filepath

Def creat_num (self):

Emplist = []

With open (self.empfile) as f:

Empf = csv.reader (f)

For emp in empf:

Emplist.append (emp)

Print ('% s people participated in the lucky draw'% len (emplist))

Levels = int (input ('lottery is divided into several levels, please enter:')

# define a dictionary

Level_dict = {}

For i in range (0J):

Print ('Please enter the number of prizes corresponding to the current winning level% s'% (I + 1))

Str_level_dict_key = sys.stdin.readline ()

Int_level_dict_key = int (str_level_dict_key)

Level_ [I] = int_level_dict_key

# after the completion of the cycle, the lottery level dictionary is constructed.

# start the raffle

Print ('lucky draw dictionary is set to% s'% level_dict)

For i in range (0jinlen (level_dict)):

Winers = []

# generate the number of raffles corresponding to the current lottery level I

For j in range (0jint (level_ quote [I])):

# generate a random one from the list using the choice function in the random module

Winer = random.choice (emplist)

Winers.append (winer)

Emplist.remove (winer)

Print (the winners produced under% s of the lucky draw are:'% (I + 1))

Print (winers)

# after the function of the class is defined, initialize and use

If _ _ name__ = ='_ _ main__':

Peoples = Choujiang ('cvv _ love _ mop. CSV')

Peoples.creat_num ()

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647

This program can be run in python 2. 6 and 3. The running result is as follows:

Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32

Type "copyright", "credits" or "license ()" for more information.

> = = RESTART = =

>

Start the lottery.

A total of 24790 people took part in the lucky draw

The lottery is divided into several levels, please enter: 2

Please enter the number of prizes corresponding to the current winning level 1

one

Please enter the number of prizes corresponding to the current winning level 2

three

The lottery dictionary is set to: {0: 1, 1: 3}

The winners under level 1 of the lucky draw are:

['Zhang San 19826']

The winners under level 2 of the lucky draw are:

[['Zhang San 18670'], ['Zhang San 23235'], ['Zhang San 15705']]

This is the end of the content of "how to develop Mini Program in the annual lottery". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report