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
Ask the user to enter a list containing numbers between 1 and 12. Then replace all of the entries in the list that are greater than 10 with 10.
Ask the user to enter a list of strings. Create a new list that consists of those strings with their first characters removed.
Create the following lists using a for loop:
A list consisting of the integers 0 through 49.
Create the following lists using a for loop:
A list containing the squares of the integers 1 through 50.