Professional Documents
Culture Documents
11 listBasedQuestions
11 listBasedQuestions
11 listBasedQuestions
L=[] #L=list()
n=int(input('How many number of elements you want to insert:'))
for i in range(n): # 0 to n-1
x=int(input('Enter a number:'))
L.append(x)
print('List:',L)
'''
#------------------------------------------------
#2.Program to create a tuple of n numbers.
t=()
n=int(input('How many number of elements you want to insert:'))
for i in range(n):
x=int(input('Enter a number:'))
t=t+(x,) #(10,20,30)
print('Tuple:',t)
#-------------------------------------------------
-------------------------------------------------------------
'''
8. Program to search an element in the list
'''
n=int(input('How many number of elements you want to insert in the list:'))
arr=[]
for i in range(n):
arr.append(int(input('Enter an element in the list:')))
print(result)
#Display names of students who have got marks more than 75
print("Student's name who get more than 75 marks is/are")
for i in result:
if result[i][1] > 75:
print(result[i][0])
---------------------------------------------------------------------
#10. Program to sort a list by using Bubble sort.
aList=[15,6,13,22,3,52,2]
print("Original list is :",aList)
n=len(aList)
for i in range(n-1):
for j in range(n-1-i):
if aList[j]>aList[j+1]:
aList[j],aList[j+1]=aList[j+1],aList[j]
print('List after Sorting:',aList)
#aList.sort()
--------------------------------------------------------------------
#11. Program to sort a list by using sort.
L=[2,4,5,1,3]
print('Unsorted List:',L)
for i in range(1,len(L)):
key=L[i]
a=i-1
while a>=0 and key<L[a]:
L[a+1]=L[a]
a-=1
else:
L[a+1]=key
print('Sorted List:',L)
------------------------------------------------------------------
'''
12. Program to count the number of strings where the string length
is 2 or more and the first and last characters are same
from a given list of strings.
L=[]
i=0
while i<7:
x=int(input('Enter a number:'))
if x<0:
print('Please enter a positive integer.')
continue
else:
L.append(x)
i+=1
print(L)
L_new=[]
for i in range(len(L)):
if L[i]%5==0:
L_new.append(L[i])
print('Original list:',L)
print('List of those numbers that are divisible by 5:',L_new)
---------------------------------------------------------------
#17.