python带你揭秘简单验证码系统的制作

python带你揭秘简单验证码系统的制作

  1. 配置环境:pycharm,python3.8,sublime
  2. 完整代码如下所示:
s='qazwsxedcrfvtgbyhnujmiklopQAZWSXEDCRFVTGBYHNUJMIKOLP0123456789'
code =''
import random
for i in range(4):
    ran =random.randint(0,len(s)-1)
    code+=s[ran]
print('验证码',code)
user_input=input('请输入验证码:')
if user_input.lower()==code.lower():
    print('验证码输入正确')
else:
    print('验证码输入错误!')

3.运行结果:
在这里插入图片描述
4.结果分析:
通过运用python随机数函数进行四次for循环来产生四个随机数字和二十六个字母大小写来产生一个验证码。为了方便运用使用lower函数使其输入大小写字母都能运行让该段代码更灵活,更加方便使用人。

猜你喜欢

转载自blog.csdn.net/weixin_48106407/article/details/107512976