Jul-30-2020, 07:03 PM
Hi Everyone,
I'm currently trying to make a password generator in python but I keep running into the same error. I've tried to change the function parameters to not be functions and call them first and input them as variables but I still can't get it to work.
This happens when I'm trying out the [1, 1, 0, 0] case
I'm currently trying to make a password generator in python but I keep running into the same error. I've tried to change the function parameters to not be functions and call them first and input them as variables but I still can't get it to work.
import random import numpy as np upperCase = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] lowerCase = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',] numbers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'] special = ['!', '@', '#','%', '^', '&', '*', '(', ')'] def length(): # determins the length of password length = int(input("How long do you want the password to be? \n")) return length def questions(): # determines which lists to use (upperCase, lowerCase, numbers, special) refList = [] uppercase = str(input("Do you want uppercase letters? \n[a] yes \n[b] no \n")) if uppercase == 'yes' or uppercase == 'a': refList.append(1) elif uppercase == 'no' or uppercase == 'b': refList.append(0) lowercase = str(input("Do you want lowercase letters? \n[a] yes \n[b] no \n")) if lowercase == 'yes' or lowercase == 'a': refList.append(1) elif lowercase == 'no' or lowercase == 'b': refList.append(0) numbers = str(input("Do you want numbers? \n[a] yes \n[b] no \n")) if numbers == 'yes' or numbers == 'a': refList.append(1) elif numbers == 'no' or numbers == 'b': refList.append(0) special = str(input('Do you want special characters? \n[a] yes \n[b] no \n')) if special == 'yes' or special == 'a': refList.append(1) elif special == 'no' or special == 'b': refList.append(0) return refList def sumOfList(sampleList): # determines whether its 2 or 3 types total = sum(sampleList) return total def determineNumbers(length, total): # determines the random amount of each list hello = length n = total rnd_array = np.random.multinomial(hello, np.ones(n)/n, size=1)[0] list1 = rnd_array.tolist() return list1 def second(refList, length): if refList == [0, 0, 0, 0]: print("Invalid answer, please try again") elif refList == [1, 0, 0, 0]: #JUST UPPER password = ''.join([random.choice(upperCase) for _ in range(length)]) print(password) elif refList == [0, 1, 0, 0]: #JUST LOWER password = ''.join([random.choice(lowerCase) for _ in range(length)]) print(password) elif refList == [0, 0, 1, 0]: #JUST NUMBERS password = ''.join([random.choice(numbers) for _ in range(length)]) print(password) elif refList == [0, 0, 0, 1]: #JUST SPECIAL password = ''.join([random.choice(special) for _ in range(length)]) print(password) elif refList == [1, 1, 0, 0]: #UPPER AND LOWER determineNumbers(length(), sumOfList(refList)) numOfUpperCase = list1[0] numOfLowerCase = list1[1] firstpw = [random.choice(upperCase) for _ in range(numOfUpperCase)] secondpw = [random.choice(lowerCase) for _ in range(numOfLowercase)] finalpw = firstpw + secondpw random.shuffle(finalpw) new = "".join(finalpw) print(new) second(questions(), length())The error I'm getting is:
This happens when I'm trying out the [1, 1, 0, 0] case
Error:Traceback (most recent call last):
File , line 96, in <module>
second(questions(), length())
File , line 85, in second
determineNumbers(length(), OfList(refList))
TypeError: 'int' object is not callable