尝试创建一个简单的密码生成器,但我的功能并没有给我想要的预期结果或结果。即没有加起来扩展空列表。我应该改变什么吗?
import random
def passstrength():
return input("Please state how strong you have the password to be? (1 = strongest, 2 = medium, 3 = weakest): ")
passstrength = passstrength()
list1 = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','q','r','s','t','u','v','x','y','z']
list2 = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','Q','R','S','T','U','V','X','Y','Z']
list3 = [1,2,3,4,5,6,7,8,9,0]
list4 = ["@","$","%","&"]
r = []
def getpass(x):
return random.sample(x,2)
def mergepass(first,second,third):
if passstrength == 1:
a = getpass(first)
b = getpass(second)
c = getpass(third)
r = (a + b + c)
return r
elif passstrength == 2:
a = getpass(first)
b = getpass(second)
r = (a + b)
return r
else:
a = getpass(first)
r = (a)
return r
print (mergepass(list1,list2,list3))
答案 0 :(得分:0)
passstrength
作为字符串传递,因此当您将其与int
进行比较时,它会失败。
您可以通过执行以下操作来解决此问题:
passstrength = int(passstrength())