目前由于无法在列表中插入值而陷入困境
在尝试输入“sex”列表时,返回以下错误:
'AttributeError:'int'对象没有'insert'属性
到目前为止我得到的是:
#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()
在main中,通过以下部分调用sexInput:
然后,函数的标题为:
所以,你改变了顺序,从而在你认为是性的东西(一个列表)中做出了选择(一个int)
相关问题 更多 >
编程相关推荐