0

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()
1
  • Variable and function names should follow the lower_case_with_underscores style. return on its own is also bad style. Overall, there is definitely some refactoring to be done. Commented Nov 28, 2019 at 4:35

1 Answer 1

2

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)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks man, didnt realise this could create errors, will keep in mind in the future

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.