python生成一个4位随机验证码
python生成一个4位随机验证码
import random
checkcode = ''
for i in range(4):
current = random.randrange(0,4)
if current == i:
tep = chr(random.randint(65,97))
else:
tep = random.randint(0,9)
checkcode+=str(tep)
print(checkcode)
区分randrange() randint()
M = random.randrange(a,b),M的取值范围是 a <= M < b
N = random.randint(a, b),N在此处的选择范围是a <= N <= b,是包含b的
所以,理论上可以理解为:randint(a,b) == randrange(a,b+1)