user12149444
user12149444

Reputation:

Cannot insert data to list - AttributeError: 'int' object has no attribute 'insert'

Currently stuck at the moment as i am unable to insert values into lists.

I am returned the following error while trying to input into list 'sex':

'AttributeError: 'int' object has no attribute 'insert''

This is what I've got so far:

#input/error handling
error = 'Error, Incorrect (format/value)'
returned = 'Returned.'
entryRem = 'Entry removed.'
na = 'N/A'

#data storage
index = [0]
sex = [0]
choice = int()

def menu():
    print('1. Input data')
    input1 = input('Input (1): ')
    if input1 == '1':
        indexSel(index)
        sexInput(sex, choice)
    else:
        print('\n',error,returned,'\n')
        menu()
        return

def indexSel(index):
    global choice
    print('Index: ',index)
    choice = len(index)
    index.append(choice)
    return

def sexInput(choice, sex):
    inSex = input("Person's Sex? (m/f)").upper()
    if inSex == 'M' or inSex == 'F':
        sex.insert(choice,inSex)
    else:
        print(entryRem,error)
    return
menu()

Upvotes: 0

Views: 399

Answers (1)

c4llmeco4ch
c4llmeco4ch

Reputation: 311

In main, you call sexInput with the following section:

if input1 == '1':
    indexSel(index) 
    sexInput(sex, choice)

Then, your header for the function reads:

def sexInput(choice, sex):

So, you switched the order, thereby making choice (an int) in what you thought would be sex (a list)

Upvotes: 2

Related Questions