Long Answer Type Questions (5 Marks each)

Computer Science - Class 11
Chapter 9 Class 11 - Lists

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.

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) ```

Get live Maths 1-on-1 Classs - Class 6 to 12

Davneet Singh

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