Posts

Showing posts from August, 2025

Python_Single_List_2_Examples

Traverse  → forward & backward Search  → find a student Update  → change a student name Add  → add at the end Delete  → remove a student Sort  → alphabetical & reverse alphabetical Reverse  → create a reversed list without using  reverse() First/Last Alphabetically  → find first and last name Count Occurrences  → count a student Insert  → insert a student at a specific position Second student alphabetically Remove first student starting with a specific letter Display students with name length greater than 4 # Single List of Students students = ["Alice", "Bobby", "Charlie", "David", "Frank", "Grace"] # ----------------------------- # 1. Traverse the list (forward) # ----------------------------- print("1. Traverse forward:") for i in range(len(students)):     print(students[i]) # ----------------------------- # 2. Traverse the list (backward) # ----------------------------- print("\n2. Traverse ba...

Python_lilst_questions_answers

MCQs (Multiple Choice Questions) 1. Which of the following creates a blank list in Python? a) l = () b) l = {} c) l = [] d) l = '' Answer: c) l = [] 2. What will be the output of the following code? l = list(range(5)) print(l) a) [0,1,2,3,4] b) [1,2,3,4,5] c) (0,1,2,3,4) d) Error Answer: a) [0,1,2,3,4] 3. Which function is used to split a string into a list in Python? a) break() b) split() c) list() d) partition() Answer: b) split() 4. If the input is "[10,20,30]" and the following code is executed: l = eval(input("Enter List:")) print(type(l)) What will be the output? a) <class 'tuple'> b) <class 'list'> c) <class 'str'> d) <class 'dict'> Answer: b) <class 'list'> 5. Which of the following correctly converts the string "python is very easy" into a list of words? a) list("python is very easy") b) "python is very easy...

Python_Multiple_Parallel_list_operations

Multiple Lists (students, maths, physics, english) You are given four parallel lists: students = ["Alice", "Bob", "Charlie", "David", "Eve"] maths = [85, 92, 78, 90, 88] physics = [80, 95, 70, 85, 89] english = [82, 88, 75, 92, 84] Write a Python program to: Search for a student’s marks in all subjects. Sort all lists by student name (A–Z). Sort in reverse by Maths marks (highest → lowest). Traverse and print student with all three subject marks. Reverse traverse the lists. Find & update a student’s marks in any subject. Delete a student and their marks from all subjects. Add a new student with marks in all subjects. Calculate total marks for each student. Calculate average marks for each student. Display a Rank List (students sorted by total marks in descending order). ____________________________________________________________________________ # Parallel lists students = ...

Python_two_parallel_lists_examples

Double List (students & marks) You are given two parallel lists: students = ["Alice", "Bob", "Charlie", "David", "Eve"] marks = [85, 92, 78, 90, 88] Step-by-Step Features for Beginners: Traverse  → forward & backward Search  → find a student’s marks Update  → change marks Add  → new student with marks Delete  → student and marks Sort  → by name & by marks Reverse  → implicitly by descending sort Max/Min  → highest and lowest marks Average  → average marks Rank List  → display sorted by marks # Single List of Students students = ["Alice", "Bobby", "Charlie", "David", "Frank", "Grace"] # ----------------------------- # 1. Traverse the list (forward) # ----------------------------- print("1. Traverse forward:") for i in range(len(students)): print(students[i]) # ----------------------------- # 2. Traverse the list (backward) # -------------------...

Python_Single_List_1_Examples

# Swap two numbers a = 5 b = 10 # Using a temporary variable to swap temp = a a = b b = temp print("a =", a) print("b =", b) ___________________________________________________________________________________ # Swap two numbers if a is bigger than b a = int ( input ("Enter A: ")) b = int ( input ("Enter B: ")) if ( a > b ):    temp = a    a = b    b = temp print ("a =", a) print("b =", b) ___________________________________________________________________________________   # Two-number toolbox with manual operations # Step 1: Initiate the list numbers = [8, 5] print("Original list:", numbers) # Step 2: Swap the two numbers manually temp = numbers[0] numbers[0] = numbers[1] numbers[1] = temp print("After swapping:", numbers) # Step 3: Find minimum manually if numbers[0] < numbers[1]:     minimum = numbers[0] else:     minimum = numbers[1] # Step 4: Find maximum manually if numbers[0] > numbers[1]:  ...