输入没有选择密码长度
input isn't choosing the passwort length
我是编程新手,正在制作密码管理器。
我的问题: - 它做了什么 -> 当我 运行 程序并输入密码长度时,它会生成一个密码,但它总是 4 位数字长,并且密码重复了我所拥有的数字很多次投放。
- 它应该做什么 -> 我输入的数字应该决定密码的长度而不是重复多少次。
import random
#shuffle the list
def shuffle(string):
tempList = list(string)
random.shuffle(tempList)
return ''.join(tempList)
#the password functions
uppercaseLetter=chr(random.randint(65,90))
lowercaseLetter=chr(random.randint(97,122))
punctuationSign=chr(random.randint(32,152))
digit=chr(random.randint(48,57))
#completing the password
passwordLength = int(input("choose your password length: "))
possibleChars = uppercaseLetter, lowercaseLetter, punctuationSign, digit
ranChar = shuffle(possibleChars)
tempPassword = []
count = 0
while count != passwordLength:
tempPassword.extend(ranChar)
count = count + 1
password = ''.join(tempPassword)
#for which sitename
sitename = input('Save under which name: ')
print (password, sitename)
data=open("test.txt",'a')
data.write(sitename +' ')
data.write(password +'\n')
data.close()
我认为你真的把你需要做的事情复杂化了,据我所知,这是你正在尝试做的事情
import random
#completing the password
passwordLength = int(input("choose your password length: "))
temp_pass = ''
count = 0
while count != passwordLength:
char_type = random.randint(0,3)
if char_type == 0:
random_char = chr(random.randint(65,90))
elif char_type == 1:
random_char = chr(random.randint(97,122))
elif char_type == 2:
random_char = chr(random.randint(32,152))
else:
random_char = chr(random.randint(48,57))
temp_pass = temp_pass + random_char
count = count + 1
print(temp_pass)
希望这对您有所帮助。我建议在尝试这样的事情之前多练习基础知识,代码中有很多不好的做法。
我是编程新手,正在制作密码管理器。 我的问题: - 它做了什么 -> 当我 运行 程序并输入密码长度时,它会生成一个密码,但它总是 4 位数字长,并且密码重复了我所拥有的数字很多次投放。 - 它应该做什么 -> 我输入的数字应该决定密码的长度而不是重复多少次。
import random
#shuffle the list
def shuffle(string):
tempList = list(string)
random.shuffle(tempList)
return ''.join(tempList)
#the password functions
uppercaseLetter=chr(random.randint(65,90))
lowercaseLetter=chr(random.randint(97,122))
punctuationSign=chr(random.randint(32,152))
digit=chr(random.randint(48,57))
#completing the password
passwordLength = int(input("choose your password length: "))
possibleChars = uppercaseLetter, lowercaseLetter, punctuationSign, digit
ranChar = shuffle(possibleChars)
tempPassword = []
count = 0
while count != passwordLength:
tempPassword.extend(ranChar)
count = count + 1
password = ''.join(tempPassword)
#for which sitename
sitename = input('Save under which name: ')
print (password, sitename)
data=open("test.txt",'a')
data.write(sitename +' ')
data.write(password +'\n')
data.close()
我认为你真的把你需要做的事情复杂化了,据我所知,这是你正在尝试做的事情
import random
#completing the password
passwordLength = int(input("choose your password length: "))
temp_pass = ''
count = 0
while count != passwordLength:
char_type = random.randint(0,3)
if char_type == 0:
random_char = chr(random.randint(65,90))
elif char_type == 1:
random_char = chr(random.randint(97,122))
elif char_type == 2:
random_char = chr(random.randint(32,152))
else:
random_char = chr(random.randint(48,57))
temp_pass = temp_pass + random_char
count = count + 1
print(temp_pass)
希望这对您有所帮助。我建议在尝试这样的事情之前多练习基础知识,代码中有很多不好的做法。