k= int(raw_input())
a.remove(a[k-1])
print "the list is ",a,' now'
p,q =map(int,raw_input("enter the position and number you want to modify:\n").split())
a[p-1] = q
print "the list is ",a,' now'
print 'enter the number you want to find in the list'
n = int(raw_input())
if n in a:
for i in range(len(a)):
if a[i] == n:
print "%d is the %dth element in the list"% (n,i+1),a
else:
print 'Not found!\n'
输出展示:
E:\Python27\python.exe D:/python/python算法/b.py
Enter the list:
1 2 3 4
The list is:
[1, 2, 3, 4]
The length of the list is: 4
Enter the position and number you want to add:
1 2
the list is [2, 1, 2, 3, 4] now
enter the position you want to remove in the list
2
the list is [2, 2, 3, 4] now
enter the position and number you want to modify:
1 5
the list is [5, 2, 3, 4] now
enter the number you want to find in the list
4
4 is the 4th element in the list [5, 2, 3, 4]
Process finished with exit code 0
收工!