Wednesday 14 February 2024

Class 11 CS Practical - 38

38 - Write a program in Python to Input a list of numbers and find the index of a specific element. 


L= [10, 20, 30, 40, 50]

print("List is : ",L)

c='Y'

while c=='Y' or c=='y':

    n=int(input("Enter the number to be search in the List: "))

    found=False

    for i in L:

        if i==n:

            print("Element found at index: ",L.index(i))

            found=True

    if found==False:

        print("Number is not found in the list")

    c=input("Do you want to search more item (Y/N): ")


Output:

List is :  [10, 20, 30, 40, 50]

Enter the number to be search in the List: 30

Element found at index:  2

Do you want to search more item (Y/N): y

Enter the number to be search in the List: 50

Element found at index:  4

Do you want to search more item (Y/N): y

Enter the number to be search in the List: 15

Number is not found in the list

Do you want to search more item (Y/N): n



No comments:

Post a Comment