zoukankan      html  css  js  c++  java
  • 简单随机验证码生成

    random 模块学习

    纯数字4位验证码:

    1 import random
    2 checkcode=''
    3 for i in range(4):
    4     current=random.randint(1,9)
    5     checkcode+=str(currenmt)
    6 print (checkcode)

    数字+大写字母 4位验证码

     1 import random
     2 checkcode=''
     3 for i in range(4):
     4     current=random.randint(1,4)
     5     if  current=i:
     6             tmp=chr(random.randint(65,90))
     7     else:
     8             tmp=random.randint(0,9)
     9     checkcode+=str(tmp)
    10 print (checkcode)

    数字+小写字母  4位验证码

     1 import random
     2 checkcode=''
     3 for i in range(4):
     4     current=random.randint(0,4)
     5     if current=i:
     6         tmp=chr(random.randint(97,122))
     7     else:
     8         tmp=random.randint(0,9)
     9     chechcode+=str(tmp)
    10 print (checkcode)

    数字+大写+小写 4位验证码:

     1 import random
     2 checkcode=''
     3 for i in range(0,4):
     4     current=random.randint(0,4)
     5     if current == 1:
     6         tmp=chr(random.randint(64,90))
     7     elif current ==2:
     8         tmp = chr(random.randint(97.122))
     9     else :
    10         tmp=random.randint(0,9)
    11         checkcode+=str(tmp)
    12 print (checkcode)

    用 if进行判断。可以多种验证码。

  • 相关阅读:
    pandas isin 和not in
    游戏开发需要学什么?
    打开页面,数字会自增的效果怎么弄?
    jq 导航栏点击添加/删除类(a标签跳转页面)
    bootstrap+jq分页
    2020/12/18
    2020/12/17
    2020/12/16
    2020/12/15
    2020/12/14
  • 原文地址:https://www.cnblogs.com/pangya/p/10071761.html
Copyright © 2011-2022 走看看