random

import random
# print(random.random())
# print(random.randint(1,8))
# print(random.choice(['123','eee',[1,2,3]]))
# print(random.shuffle)
# print(random.sample(['123',4,[1,2]],2))
# print(random.randrange(1,4))

#验证码函数
def v_code():
code = ' '
for i in range(5):
#if i == random.randint(0,2):
j = random.randrange(0,2)
if j == 0:
b = random.randrange(10)
else:
b = chr(random.randrange(65,91))
code+=str(b)
print(code)

v_code()

#print(chr(97)) 将97变成对应的ascII码表中的字符

def v_code2():
code = ''
for i in range(5):
add = random.choice([random.randrange(10),chr(random.randrange(65,91))])
code += str(add)
print(code)
v_code2()
posted @ 2019-07-09 14:48  python小白丶  阅读(190)  评论(0编辑  收藏  举报