【问题标题】:Any idea why my functions are not working?知道为什么我的功能不起作用吗?
【发布时间】:2017-12-04 06:05:49
【问题描述】:

试图创建一个简单的密码生成器,但我的功能并没有给我想要的预期结果或结果。 IE。不加起来以扩展空列表。我应该改变什么吗?

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))

【问题讨论】:

    标签: python function addition


    【解决方案1】:

    passstrength 作为字符串传递,因此当您将其与int 进行比较时,它会失败。

    您可以通过以下方式修复它:

    passstrength = int(passstrength())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-11
      • 2016-02-15
      • 1970-01-01
      • 2016-08-25
      • 1970-01-01
      相关资源
      最近更新 更多