随机验证码

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:YanceChan
#内置函数2

# callable()#判断函数是否可调用
# chr()#asscii表里的对应关系,数字转字母
# ord()#asscii表里的对应关系,字母转数字


# 随机生成7位验证码
import random
li = []
for i in range(7):
    r = random.randrange(0,5)
    if r ==2 or r ==4:
        num = random.randrange(0,10)
        li.append(str(num))
    else:
        tmp = random.randrange(65,91) #在括号后面的范围内随机获得,65-90为A-Z的ascii表对应数值
        c = chr(tmp)
        li.append(c)
ret = "".join(li)
print(ret)#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:YanceChan
# 2、需求:定义函数统计一个字符串中大写字母、小写字母、数字的个数,并返回结果
oStr = input('请输入一串字符:')

uppstr_num = 0
lowstr_num = 0
digit_num = 0
othstr_num = 0
for strs in oStr:
    if strs.isupper():
        uppstr_num +=1
    elif strs.islower():
        lowstr_num +=1
    elif strs.isdigit():
        digit_num +=1
    else:
        othstr_num +=1

print('大写字母有:%d' %uppstr_num)
print('小写字母有:%d'%lowstr_num)
print('数字有:%d'%digit_num)
print('其他字符有:%d'%othstr_num)



阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页