Write a program to search a number entered by a user in list of 100 numbers and then print the index position of that number. Now swap it with the number 10 places previous to it.
Answer:
Code:
list1=[]
f=
-1
for i in range(
100
):
list1.append(int(input(
"enter a number"
)))
search=int(input(
"enter the number to be searched"
))
for i in range(
100
):
if (search==list1[i]):
f=i
break
if (f==
-1
):
print(
"Number not found"
)
else:
print(
"Number found at"
, f)
a=list1[f]
list1[f]=list1[f
-10
]
list1[f
-10
]=a
print("New list is", list1)