Day7_Practice

import os
import time

"""
Author:黄骏捷
Date:2019-09-29

练习1:在屏幕上显示跑马灯文字
"""
def main():
    content = 'python真好玩。。。...'
    while True:
        os.system('cls')
        print(content)
        #休眠200毫秒
        time.sleep(0.2)
        content = content[1:] + content[0]

if __name__ == '__main__':
    main()

"""
练习2:设计一个函数产生指定长度的验证码,验证码由大小写字母和数字构成
"""
def generate_code(code_len=4):
    """
    生成指定长度的验证码

    :param code_len: 验证码的长度(默认4个字符)

    :return: 由大小写英文字母和数字构成的随机验证码
    """
    all_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    last_pos = len(all_chars) - 1
    code = ''
    for _ in range(code_len):
        index = random.randint(0, last_pos)
        code += all_chars[index]
    return code
发布了66 篇原创文章 · 获赞 45 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/ACofKing/article/details/101792559