Learn practical skills, build real-world projects, and advance your career
Updated 3 years ago
!pip install jovian --upgrade --quiet
import jovian
Question 1: The user will enter a list of numbers and a separate number. The program will display the index at which the number is present in the list. If the number is absent, it'll return -1. Do NOT use built-in functions for searching.
def find(L,x):
flag = 0
for i in range(len(L)): #search to find the nunber x in the list
if L[i] == x:
print(i)
flag = flag + 1
if flag == 0: # condition for no such number in list
return -1
Enter the number of terms in the list: 3
Enter the 1 term1
Enter the 2 term2
Enter the 3 term3
Enter the number to search: 2
1
L = [] #input the list and number to find
n = int(input("Enter the number of terms in the list: "))
message = "Enter the {} term"
for i in range(1,n+1):
y = int(input(message.format(i) ))
L = L + [y]
x = int(input("Enter the number to search: "))
find(L,x)