Posts

Showing posts with the label BCA Semester 6

Sorting and Searching Programs in Python

SORTING Bubble Sort: def bubble_sort(nums):     # We set swapped to True so the loop looks runs at least once     swapped = True     while swapped:         swapped = False         for i in range(len(nums) - 1):             if nums[i] > nums[i + 1]:                 # Swap the elements                 nums[i], nums[i + 1] = nums[i + 1], nums[i]                 # Set the flag to True so we'll loop again                 swapped = True # Verify it works # nums = [5, 2, 1, 8, 4] nums = input('Enter the list of numbers: ').split() nums = [int(x) for x in nums] bubble_sort(nums) print("List Sorted using Bubble Sort") print(nums) Output: Enter the list of numbers: 5 23 3 65 74 55 List Sorted using Bubble Sort [3, 5, 23, 55, 65, 74] Selection Sort: def selection_sort(nums):     # This value of i corresponds to how many values were sorted     for i in range(len(nums)):         # We assume that the first item of th

Python Programming Question Bank

Python Programming Question Bank 1.            Explain the Data Types available in Python. 2.            Explain Looping statements in Python. Give examples of while and for loop. 3.            Explain the use of Global and Non-Local variables with example. 4.            Explain Scoping for local variable in python. 5.            Differentiate List and Tuple. 6.            Explain Slicing of strings in python using examples. 7.            Explain List in Python. 8.            Explain Tuples in Python with example. 9.            Explain Dictionary in Python with example. 10.       What is the difference between = = and is operator in Python? 11.       Explain branching and iteration operation in python with example. 12.       What is Specifications? Explain docstring in python. 13.       What is function? Explain default argument using suitable example. 14.       What is module? Discuss various ways to use module in a python program. 15.       What is