1. 程式人生 > >python之生成隨機密碼

python之生成隨機密碼

input pytho range 生成 pre 設置 please imp cnblogs

#!/usr/bin/python
#-*-conding:utf-8-*-

#密碼隨機生成器,密碼長度由用戶輸入,用戶可以自己設置密碼長度
import random
import string

def getRandompwd(pwd_length):
    password = ‘‘
    for i in range(pwd_length):
        password = str(password + str(random.randrange(0,10)))
    print(password)
        

pwd_length = int(input("please input the password length:"))
getRandompwd(pwd_length)

運行:

please input the password length:6
077558

python之生成隨機密碼