Computer Science

Write a program to check if a number is present in the list or not. If the number is present, print the position of the number. Print an appropriate message if the number is not present in the list.

Python

Python List Manipulation

73 Likes

Answer

l = eval(input("Enter list: "))
n = int(input("Enter number to search: "))

if n in l:
    print(n, "found at index", l.index(n))
else :
    print(n, "not found in list")

Output

Enter list: [1, 3, 15, 8, 20]
Enter number to search: 15
15 found at index 2

=====================================

Enter list: [1, 3, 15, 8, 20]
Enter number to search: 25
25 not found in list

Answered By

31 Likes


Related Questions