Category: Python

  • Difference between range() and xrange() in Python

    Introduction This article illustrates the Difference between range() and xrange() in Python . Both the range() and the xrange() functions are used to determine the number of iterations that a loop will undergo. Especially in for loops, these methods are used to determine the range of iteration of the loops. The xrange() method is not…

  • Switch Case Replacement in Python

    Switch Case in Python Switch Case is a very popular concept that a lot of programmers use as a conditional operation. Most common languages like C/ C++, and Java, among others, have a switch statement. However, in Python, the switch case statement is not available. Therefore, in this article, we will try to create our…

  • Using Else conditional Statement with for loop in Python

    Introduction This article will illustrate how to use else statements when using for in loop in Python. In most common programming languages like C/C++, Java, etc., we see that the use of else is only followed by an if statement. If an if statement is not present, then the else statement cannot be singularly used.…

  • Chaining Comparison Operators in Python

    Introduction This article illustrates how to use chaining comparison operators in Python. In all programming languages, we are often faced with situations where we want to check more than two conditions at a time. A simple example can be to find out the largest or smallest out of three numbers. a < b < c?…

  • Best Python Libraries for Quantitative Finance

    Best Python Libraries for Quantitative Finance

    Introduction Python is the most popular coding language for people who work in quantitative finance. Investors, asset managers, and investment bankers use it for tasks that range from high-frequency trading to rebalancing portfolios. While users may prefer Python because it is easy to read and understand, it also has numerous libraries that can be imported…

  • 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 the top of larger disks.…

  • Program to print smallest m digit number divisible by n using Python

    Introduction The task to find and print the smallest M digit number divisible by N. Program def result(n, m):     x = pow(10, m-1)        if( x % n == 0):         print(x)          else:         print((x + n) – ((x + n) % n))    n = 64  m = 8  result(n, m)…

  • Program to find product of unique prime factors of a given number using Python

    Introduction The task is to print the product of unique prime factors of the given number. Program def find(ip_num): # Initializing product with 1     prod = 1     for num in range(2, ip_num+1):         if (ip_num % num == 0):             prime_true = 1                          for num2 in range(2, int(num/2 + 1)):                 if…

  • 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 in range(ip_num + 1)]…

  • 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, length):     print(ip_array[n][m])  #Print diagonals          l = 1 for…