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 insertion sort

To write a Python Program to perform insertion sort.  def insertion_sort(alist):    for i in range(1, len(alist)):        temp = alist[i]        j = i – 1        while (j >= 0 and temp < alist[j]):            alist[j + 1] = alist[j]        […]

Python Program to perform selection sort

To write a Python Program to perform selection sort. def selection_sort(alist):    for i in range(0, len(alist) – 1):        smallest = i        for j in range(i + 1, len(alist)):            if alist[j] < alist[smallest]:                smallest = j    […]

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 […]

Python program to find the exponentiation of a number

To write a Python program to find the exponentiation of a number.  number = int(input(” Please Enter any Positive Integer : “))exponent = int(input(” Please Enter Exponent Value : “))power = 1 for i in range(1, exponent + 1):    power = power * number print(“The Result of {0} Power {1} = {2}”.format(number, exponent, power)) […]

Python program to find GCD of two numbers

To write a Python program to find GCD of two numbers.  # Python Program to find GCD of Two Numbersa = float(input(” Please Enter the First Value a: “))b = float(input(” Please Enter the Second Value b: “))i = 1while(i <= a and i <= b):    if(a % i == 0 and b % […]

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.