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 seperate 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.
#Taking user input of numbers of list
list=[]
num=int(input("Enter number of elements in the list:"))
for i in range(num):
a1=int(input("Enter a number in the list"))
list.append(a1)
print(list)
#Entering the seperate number whose index is to be found
number_to_be_matched=int(input("enter the whose index you want to see in the list"))
# Checking the number in the list and finding its index number
flag=0
for i in range(num):
if list[i]==number_to_be_matched:
print("The index number of the entered number is {} ".format(i))
flag=1
break
if flag!=1:
print('1')
Enter number of elements in the list:5
Enter a number in the list4
Enter a number in the list5
Enter a number in the list6
Enter a number in the list8
Enter a number in the list7
[4, 5, 6, 8, 7]
enter the whose index you want to see in the list6
The index number of the entered number is 2
Question 2: The user will enrer a list of numbers the program should return the third largest number. Do NOT sort the list. Your program should display 0 if the list has insufficient numbers.
#Taking user input of numbers of list
list1=[]
num=int(input("Enter number of elements in the list:"))
for i in range(num):
a1=int(input("Enter a number in the list"))
list1.append(a1)
print(list1)
#Finding the third largest number
if num>2:
for i in range(1,3):
for i in range(0,list1.count(max(list1))):
list1.remove(max(list1))
print ("Third maximum number of the list is ", max(list1))
else:
print("0")
Enter number of elements in the list:6
Enter a number in the list2
Enter a number in the list4
Enter a number in the list1
Enter a number in the list4
Enter a number in the list6
Enter a number in the list2
[2, 4, 1, 4, 6, 2]
Third maximum number of the list is 2