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)

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.