Learn practical skills, build real-world projects, and advance your career
Created 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.
lst=[]
while True:
a=input("want to enter more list elements(y/n):")
if a=='y':
b=input("enter element:")
lst.append(b)
else:
break
num=input("enter the number:")
#c=len(lst)
#print(c)
if num in lst:
b=len(lst)
for m in range(0,b):
#print(m)
if num==lst[m]:
print("index of the number in the given list is ",m)
else:
print(-1)
want to enter more list elements(y/n):y
enter element:2
want to enter more list elements(y/n):y
enter element:4
want to enter more list elements(y/n):y
enter element:5
want to enter more list elements(y/n):n
enter the number:5
index of the number in the given list is 2