Int Object is not callable - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Int Object is not callable (/thread-28702.html) |
Int Object is not callable - manutd_to - Jul-30-2020 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. 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
RE: Int Object is not callable - Yoriz - Jul-30-2020 Added some comments 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)) # you cant call length here because this is the result numOfUpperCase = list1[0] # list1 is not defined numOfLowerCase = list1[1] # list1 is not defined firstpw = [random.choice(upperCase) for _ in range(numOfUpperCase)] secondpw = [random.choice(lowerCase) for _ in range(numOfLowercase)] # ironic because the case numOfLowercase does not match numOfLowerCase finalpw = firstpw + secondpw random.shuffle(finalpw) new = "".join(finalpw) print(new) second(questions(), length()) # here you pass in the result of calling length RE: Int Object is not callable - deanhystad - Jul-30-2020 length()? Where is the length() function defined? Why are you complicating things by doing this: Instead ofQuote:Do you want uppercase letters (y/n)?Adding [a] and [b] makes the prompt longer, adds confusion to what you should enter ('yes' or 'a'?) and adds extra code to handle the unnecessary confusion. RE: Int Object is not callable - manutd_to - Jul-30-2020 The length function is defined at the top, its the first function defined. Didn't realize that makes it more confusing/longer, thanks for the input, I"ll keep that in mind for next time. RE: Int Object is not callable - perfringo - Jul-30-2020 Let Python do the typing (a.k.a. built-in module string constants): >>> import string >>> string.ascii_lowercase 'abcdefghijklmnopqrstuvwxyz' >>> string.ascii_uppercase 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' >>> string.digits '0123456789' >>> string.punctuation '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' RE: Int Object is not callable - deanhystad - Jul-30-2020 (Jul-30-2020, 08:16 PM)manutd_to Wrote: The length function is defined at the top, its the first function defined. Didn't realize that makes it more confusing/longer, thanks for the input, I"ll keep that in mind for next time. But isn't length also the name of a function argument? Which do you think takes precedence, some global function outside local scope, or a local function argument? RE: Int Object is not callable - manutd_to - Jul-30-2020 Ahh so I should change the local argument to a different name? |