密码生成

创建randpass.py脚本,要求如下:

  1. 编写一个能生成8位随机密码的程序
  2. 使用random的choice函数随机取出字符
  3. 改进程序,用户可以自己决定生成多少位的密码
rom random import choice # 只需要random模块中的choice

from string import ascii_letters,digits
def randpass(n=8):

    all_chs= ascii_letters + digits
    result = ''
    for i in range(n):
        result += choice(all_chs)

    return result

if __name__ == '__main__':
    print(randpass())
    print(randpass(4))
原文地址:https://www.cnblogs.com/lsgo/p/10529692.html