如何将名称添加到我创建的列表中的某个位置?该列表被称为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
我真的不知道你刚刚问了什么。请你能解释一下 –