如何將名稱添加到我創建的列表中的某個位置?該列表被稱爲names
。如果該位置已被採納,我想用新名稱覆蓋該位置。列表中只能有10個名字。在特定位置插入列表
這是代碼:
names = []
while True:
print ('1 = Add Name ')
print ('2 = Display List ')
print ('3 = Quit \n')
choice = input('What would you like to do: ')
if choice == '1':
number=input('Enter name: ')
position= input('What position in the list would you like to add to: ')
names.append(name) # what should i do here
if(len(names) > 11):
print("You cannot enter more names")
continue
if choice == '2':
print(names)
continue
if choice == '3':
print('Program Terminating')
break
else:
print('You have entered something invalid please use numbers from 1-3 ')
continue
我真的不知道你剛剛問了什麼。請你能解釋一下 –