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.
input_int= input("Enter a list elements separated by space ")
print("\n")
userList = input_int.split()
print(" the list is: ", userList)
b = str(input("Enter a number : "))
if b in userList:
print(userList.index(b))
else:
print ("-1")
Enter a list elements separated by space 1 2 3 4 5
the list is: ['1', '2', '3', '4', '5']
Enter a number : 7
-1
n=int(input("Enter the number of elements: "))
a =list(map(float,input("\n Enter the numbers: ").strip().split()))[:n]
print("list of elements is:",a)
search_number=int(input("Enter the number to be searched: "))
for i in range (0,n):
if a[i]== search_number:
print("the index of number is",i)
exit(0)
print("-1")
exit(-1)
Enter the number of elements: 4
Enter the numbers: 1 2 3 5
list of elements is: [1.0, 2.0, 3.0, 5.0]
Enter the number to be searched: 4
-1