代码可这样写:
def main():
global numberList
numberList = [2, 0, 2, 1, 0, 7, 0, 8, 1, 3, 1, 4]
while True:
print('1.Add the number to the list and return.\n2.Delete the number in the list and return.\n3.Check if the number is in the list and return True or False.\n4.Change the value of the list and return.\n0.quit')
option=input('please input a option(0,1,2,3,4):')
if option=='1':
print(f'numberList:{add_ele()}')
elif option=='2':
print(f'numberList:{del_ele()}')
elif option=='3':
print(check_ele())
elif option=='4':
print(f'numberList:{change_ele()}')
elif option == '0':
break
def add_ele():
global numberList
x=int(input('Input a number to add:'))
numberList.append(x)
return numberList
def del_ele():
global numberList
x=int(input('Input a number to delete:'))
for a in numberList:
if a==x:
numberList.remove(a)
return numberList
def check_ele():
global numberList
x=int(input('Input a number to search:'))
if x in numberList:
return True
else:
return False
def change_ele():
global numberList
x=int(input('Input a number to change to 0:'))
new=[]
for a in numberList:
if a==x:
new.append(0)
else:
new.append(a)
return new
main()
如有帮助,请点采纳。