Program for Tower of Hanoi using Python

Introduction The task is to solve Tower of Hanoi problem using python programming. There are set of rules to follow while solving the problem: At a time only one disk is allowed to be moved. Only the uppermost disk is allowed to be moved. Disks can only be placed on...

Program for Sieve of Eratosthenes using Python

Introduction The task is to print all the prime numbers smaller than or equal to the given number n (given n must be small).   Program def SOE(ip_num): # Initialize all the element with True, the value will be False if p_num[val] is not prime     p_num = [True for val...

Program to print the matrix in Z form using Python

Introduction Given a matrix of size n*n, the task is to print the elements in Z form. Program ip_array = [[1, 2, 3],                     [4, 5, 6],                     [7, 8, 9]] length = len(ip_array[0]) #Print first line                   n = 0 for m in range(0,...