Python Practice Progress: 21/50 Questions Solved

🐍 Python Practice Progress ( 21 out of 50 question solved) Here are the problems I recently solved: ✅ Count even and odd numbers in a list ✅ Reverse a list without using reverse() ✅ Insert the third largest number at the second last position in a list. ✅ Find the sum of all elements in a list ✅ Merge two lists ✅ Find common elements between two lists ✅ Sort a list without using sort() Working through these exercises helped reinforce concepts like: • loops and indexing • list operations • conditional logic • problem-solving without relying on built-in shortcuts Sometimes going back to the basics is the best way to build stronger foundations. Day 3 ------------------- Count even and odd numbers in a list. try:     Num1=[1,2,3,4,5,6,7,8,9,9,88]     even=0     odd=0     for i in Num1:         if i%2==0:             even=even+1         elif i%2!=0:             odd=odd+1     print("even are ",even)     print("odd are ", odd) except ValueError:     print("Some error occured.") Reverse a list without using reverse(). list1=[1,2,3,4,5,6,7] rev_list=[] rev_list=list1[::-1] print(rev_list) # or try:     list1=[1,2,3,4,5,6,7]     rev_list=[]     for i in list1:         rev_list.insert(0,i)     print(rev_list) except ValueError:     print("error occured.") or try:     list1=[1,2,3,4,5,6,7]     rev_list=[]     for i in range(len(list1)-1,-1,-1):         rev_list.append(list1[i])     print(rev_list) except ValueError:     print("error occured.") Insert third largest number in a list and add it at second last position. try: list1=[1,2,76,84,989,23,4,5,666,7,788,8,9897] third_largest=sorted(list1)[-3] list1.insert(len(list1)-1,third_largest) print(list1) Find the sum of all elements in a list. try:     list1=[2,4,5,4,44,33,65,898,90]     s=0     for i in list1:         s=s+i     print(s) except ValueError:     print("error occured") Merge two lists. try:     list1=[2,3,4,4,5,6,7]     list2=[99,8,0,4,2,1]     c=list1+list2     print(c) except ValueError:     print("error occured") using extend method try:     list1=[2,3,4,4,5,6,7]     list2=[99,8,0,4,2,1]     list1.extend(list2)     print(list1) except ValueError:     print("error occured") # Find common elements between two lists. try:     list1=[2,3,4,4,5,6,7]     list2=[99,8,0,4,2,1]     list3=set(list1).intersection(set(list2))     print(list(list3)) except ValueError:     print("error occured") Sort a list without using sort(). try:         list2=[99,8,0,4,2,1]         for i in range(len(list2)):         for j in range(len(list2)-1):             if list2[j]>list2[j+1]:                 list2[j],list2[j+1]=list2[j+1],list2[j] ---i am using bubble sort logic     print(list2) except ValueError:     print("error occured") #Python #CodingPractice #PythonProgramming #ProblemSolving #DataScienceJourney

To view or add a comment, sign in

Explore content categories