我正在尝试创建一个密码生成器,并希望用户决定它应该有多长时间。在“genPassword”的第一行中,它表示元组不能被解释为整数。它是关于范围函数的吗?
num = ()
password = []
def getNumCharacters(num):
num = int(input("How many characters long do you want your password?(1-10)"))
return;
def genPassword(num, password):
for i in range(num):
password = password.insert(0, random.randint(0,9))
答案 0 :(得分:0)
您的功能不会返回任何内容。试试这个:
import random
def getNumCharacters():
return int(input("How many characters long do you want your password?(1-10)"))
def genPassword(num):
return ''.join(str(random.randint(0, 9)) for i in range(num))
num = getNumCharacters()
result = genPassword(num)
答案 1 :(得分:0)
因为你这样做:
range(())
你必须输入整数到范围,而不是空元组:
num = 20
for i in range(num):
.....