Python randomly generated 6-digit verification Code

Source: Internet
Author: User

#!/usr/bin/env python# -*- coding: utf-8 -*-#用于生成随机数的模块: random# function chr () returns the corresponding ASCII character, Contrary to the Ord () effect. import random# generates a random number num = random.randint (1,100) #随机生成一个大写字母 between 1-100, and the ASCII code value 65-90 corresponds to a-zcap =  CHR (Random.randint (65,90)) #随机生成一个小写字母, the ASCII code value 97-122 corresponds to A-ZLOW = CAP = CHR ( Random.randint (97,122)) #下面定义一个验证码生成的函数def  verification_code ():    num =  Random.randint (100,1000)     capa = chr (Random.randint (65,90))      CAPB = CHR (Random.randint (65,90))     LOW = CHR (Random.randint ( 97,122))     vercode = capa + str (num)  + capb + low     return vercode     #第二种定义def  ver ():     ver = []    for i in range (6):         if i == random.randint (1,9):             ver.append (Random.randint (1,9))         else:             temp = random.randint (65,90)              ver.append (Chr (temp))     code =   ". Join (ver)     return code         print  ' Verification Code:%s '  % verification_code () print  ' captcha: ',  ver () #第三种定义 (Recommended Practice) ' Randrange () The   method returns a random number in the specified increment cardinality collection, and the cardinality default value is 1. random.randrange  ([start,] stop [,step]) parameter     start --  start value within the specified range, contained within the range.     stop --  the end value within the specified range, not contained within the range.     step --  specifies the increment cardinality. The Randrange () and Randint () differ from the random module by specifying a cardinality, which defaults to 1 "checkcode = " "For i iN range (6):     current = random.randrange (0,9,2)     if  CURRENT != I:        TEMP = CHR ( Random.randint (65,90))     else:        temp =  random.randint (0,9)     checkcode += str (temp) Print checkcode


This article is from the "Fa&it-Q Group: 223843163" blog, please be sure to keep this source http://freshair.blog.51cto.com/8272891/1870789

Python randomly generated 6-digit verification Code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.