Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Int Object is not callable
#1
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
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
Reply
#2
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
Reply
#3
length()? Where is the length() function defined?

Why are you complicating things by doing this:
Output:
Do you want uppercase letters? [a] yes [b] no
Instead of
Quote: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.
Reply
#4
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.
Reply
#5
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
'!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#6
(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?
Reply
#7
Ahh so I should change the local argument to a different name?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  error in class: TypeError: 'str' object is not callable akbarza 2 607 Dec-30-2023, 04:35 PM
Last Post: deanhystad
  TypeError: 'NoneType' object is not callable akbarza 4 1,149 Aug-24-2023, 05:14 PM
Last Post: snippsat
  [NEW CODER] TypeError: Object is not callable iwantyoursec 5 1,520 Aug-23-2023, 06:21 PM
Last Post: deanhystad
  Need help with 'str' object is not callable error. Fare 4 915 Jul-23-2023, 02:25 PM
Last Post: Fare
  TypeError: 'float' object is not callable #1 isdito2001 1 1,131 Jan-21-2023, 12:43 AM
Last Post: Yoriz
  'SSHClient' object is not callable 3lnyn0 1 1,237 Dec-15-2022, 03:40 AM
Last Post: deanhystad
  TypeError: 'float' object is not callable TimofeyKolpakov 3 1,567 Dec-04-2022, 04:58 PM
Last Post: TimofeyKolpakov
  API Post issue "TypeError: 'str' object is not callable" makeeley 2 2,009 Oct-30-2022, 12:53 PM
Last Post: makeeley
  Merge htm files with shutil library (TypeError: 'module' object is not callable) Melcu54 5 1,710 Aug-28-2022, 07:11 AM
Last Post: Melcu54
  [split] TypeError: 'int' object is not callable flash77 4 2,834 Mar-21-2022, 09:44 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020