欢迎大家来到IT世界,在知识的湖畔探索吧!
第一种是循环控制语句和逻辑判断语句写出来的
import random import math alpha = "abcdefghijklmnopqrstuvwxyz" num = "0" special = "@#$%&*" pass_len = int(input("Enter Password Length: ")) alpha_len = pass_len // 2 num_len = math.ceil(pass_len*30 / 100) special_len = pass_len - (alpha_len + num_len) password = [] def generate_pass(length, array, is_alpha=False): for i in range(length): index = random.randint(0, len(array) - 1) character = array[index] if is_alpha: case = random.randint(0,1) if case == 1: character = character.upper() password.append(character) generate_pass(alpha_len, alpha, True) generate_pass(num_len, num) generate_pass(special_len, special) random.shuffle(password) gen_password = "" for i in password: gen_password = gen_password + str(i) print(gen_password)
欢迎大家来到IT世界,在知识的湖畔探索吧!
第二种是用调用函数实现
欢迎大家来到IT世界,在知识的湖畔探索吧!import random import string total = string.ascii_letters + string.digits + string.punctuation length = 16 password = "".join(random.sample(total, length)) print(password)
参考资料链接:
https://github.com/Python-World/python-mini-projects/tree/master/projects/Random_password_generator
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://itzsg.com/57888.html