Category: Python

Python program Merge sort

To write a Python Program to perform Merge sort. def merge_sort(alist, start, end):    ”’Sorts the list from indexes start to end – 1 inclusive.”’    if end – start > 1:        mid = (start + end)//2        merge_sort(alist, start, mid)        merge_sort(alist, mid, end)        merge_list(alist, […]

Python program to find first n prime numbers

To write a Python program to find first n prime numbers. # change the values of lower and upper for a different resultlower =  int(input(“Enter number starting: “)) upper =  int(input(“Enter number ending: “))  print(“Prime numbers between”,lower,”and”,upper,”are:”) for num in range(lower,upper + 1):   # prime numbers are greater than 1   if num > 1:      […]

Python Program to perform binary search

To write a Python Program to perform binary search.  def binary_search(alist, key):    “””Search key in alist[start… end – 1].”””    start = 0    end = len(alist)    while start < end:        mid = (start + end)//2        if alist[mid] > key:            end = […]

Python Program to perform Linear Search

To write a Python Program to perform Linear Search  def linear_search(alist, key):    “””Return index of key in alist. Return -1 if key not present.”””    for i in range(len(alist)):        if alist[i] == key:            return i    return -1 alist = input(‘Enter the list of numbers: ‘)alist […]

How to run a Python Program

Step 01: Open a textpad or notedpad. Step 02:Type your program in text editor. Step 03:Save the text file with “.py” extension as “professor.py”. py extetion is for Python file. Step 04:File will look like this. Open it. Step 05:Do right click and select edit. Step 06:Python file will get open as shown. Step 07:Click on […]

Download Python

PYTHON DOWNLOAD AND INSTALLATION Go to https://www.python.org/ See the image Now click on Download Python. Version may change with time. On donwlaod Python setup will look like this. Follow the steps to install it.