python3 随机生成6位数的验证码

要求是数字:0~9 及大小写字母。

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Hiuhung Wan

import random

# 48--57 : 0-9
# 65--90 : A-Z
# 97--122: a-z

index = 6
count = 0
str1 = ''   #存放验证码

while index > count:
    num = random.randrange(48,122)
    if (num <= 57) or (num >= 65 and num <= 90) or (num >= 97):   #符合条件
        str1 += chr(num)
        count += 1

print(str1)

  

 

效果如下

C:\Python36\python.exe D:/Py/1704/day04/随机验证码.py
YpEDP0

Process finished with exit code 0

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-06
  • 2021-07-26
  • 2022-02-11
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
相关资源
相似解决方案