Computer Science, asked by rgs012070, 4 months ago

( python) Write a program to read a list of n numbers and to search on the list.( write input and output also please)​

Answers

Answered by saurabhprabhakar3434
0

Answer:

lst = []

# number of elemetns as input

n = int(input("Enter number of elements : "))

# iterating till the range

for i in range(0, n):

ele = int(input())

lst.append(ele) # adding the element

print(lst)

Explanation:

Run it on Online GDB compiler

Answered by anindyaadhikari13
1

Required Answer:-

Question:

  • Write a program in Python to read a list of n numbers and search for an element on the list.

Solution:

Here comes the códe.

n=int(input("How many elements? "))

l=[]

print("Enter them..")

for i in range(n):

l.append(int(input("Enter:  ")))

x=int(input("Enter the element to be searched for: "))

if x in l:

print("Found at index:",l.index(x))

else:

print("Not Found.")

Algorithm:

  1. START
  2. Accept n elements and store them in list.
  3. Ask the user the element to be searched for.
  4. Check if the element is present in the list or not and display the message accordingly.

Note: The index(x) function returns the index of x present in the list. For example, if x is present in first position of list a, then a.index(x) = 0.

Refer to the attachment for output ☑.

Attachments:
Similar questions