提问人:Feb Anene 提问时间:11/16/2023 最后编辑:Feb Anene 更新时间:11/16/2023 访问量:26
如何获取参数的总和,以便将其分配给变量?
How do I get the sum of my parameters so I can assign it to a variable?
问:
import string
import secrets
import random
def password_gen(num_letters, num_digits, num_special_char):
password_length = num_letters + num_digits + num_special_char #Better way to do this?
password = []
print("Welcome to Password Generator, your desired password length is", password_length)
print("Your password will now be generated...")
for i in range(num_letters):
password.append(secrets.choice(string.ascii_letters))
for i in range(num_digits):
password.append(secrets.choice(string.digits))
for i in range(num_special_char):
password.append(secrets.choice(string.punctuation))
random.shuffle(password)
print("Your generated password is", "".join(password))
password_gen(6, 1, 3)
尝试使用 zip() 和 sum(),但出现 TypeErrors,例如 +: 'int' 和 'tuple'' 不支持的操作数类型
答: 暂无答案
评论
len(password)