首页 > 移动平台 > 详细

Python生成随机五位数——模仿手机验证码

时间:2019-05-05 13:39:49      阅读:348      评论:0      收藏:0      [点我收藏+]
使用Python生成随机的五位手机验证码。

# -*- coding:utf-8 -*-

#生成五位随机数,模仿手机验证码

#导入random库,可以生成随机数
import random

def ran():
     L = []
     M = []
#通过遍历5次,生成五个元素,并插入列表L
     for i in range(5):
             L.append(random.randint(0,9))
             if len(L) >= 5:
                     break

#通过遍历将L的五个元素由数字转为字符串,导入空列表M,并使用join方法合成为字符串     
     for d in L:
             M.append(str(d))
     S = ‘‘ .join(M)

     print(S)

#调用函数ran()
ran()

Python生成随机五位数——模仿手机验证码

原文:https://blog.51cto.com/11433338/2389104

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!