Python Math floor(), ceil(), trunc(), and modf()

This article is the first of several articles discussing functions from the math module from the Python Standard Library. The articles are organized thematically; functions that are closely related to each other are discussed in the same article. In this article, we discuss four functions: math.floor, math.ceil, math.trunc, and math.modf. They are all related to … Read more

The Sieve of Eratosthenes in Python

Finding prime numbers is of critical importance for practical applications such as cryptography. Many public-key methods are only safe from a cryptographic point of view because it’s generally inefficient and slow to compute the prime factors of large numbers. As you go over the article, feel free to watch my explainer video on the Sieve … Read more

Python math.factorial()

This article is an edited version of this article on the Finxter blog. The math.factorial() function is one of many functions in the math module. In this article, we will explore the mathematical properties of the factorial function using Python’s Matplotlib and NumPy libraries. What is the Factorial Function? A factorial of a positive integer … Read more

Python math.factorial()

The Python installation comes with its own library of functions. The factorial function math.factorial() is included with its math module. Math modules are part of the Python install code package. Math modules or functions such as factorial, square root, sine, and exponential may be used in Python programs. To use them, the import command must … Read more

bootstrap_plot() – Pandas Plotting Module

A bootstrap plot is a graphical representation of uncertainty in a characteristic chosen from within a population. While we can usually calculate data confidence levels mathematically, gaining access to the desired characteristics from some populations is impossible or impracticable. In this case, bootstrap sampling and the bootstrap plot come to our aid. This article will … Read more

Python Print Octal Without ‘0o’

Problem Formulation If you print an octal number, Python uses the prefix ‘0o’ to indicate that it’s a number in the octal system and not in the decimal system like normal integers. However, if you already know that the output numbers are octal, you don’t necessarily need the ‘0o’ prefix. How to print oct numbers … Read more

Python Print Hex Without ‘0x’

Problem Formulation If you print a hexadecimal number, Python uses the prefix ‘0x’ to indicate that it’s a number in the hexadecimal system and not in the decimal system like normal integers. However, if you already know that the output numbers are hexadecimal, you don’t necessarily need the ‘0x’ prefix. How to print hex numbers … Read more

How to Display a 1D and 2D Multiplication Table in Python?

Python Multiplication Table For Loop To calculate the multiplication table for a given number, iterate over all values i=0, 1, …, limit in a for loop and use the following statement as a loop body: print(number, ‘x’, i, ‘=’, number * i). This prints all equations, line by line, in the form i x j … Read more

Python Subtraction Operator

Python provides the subtraction operator – to subtract one object from another. The semantics of the subtraction depends on the operands’ data types. For example, subtracting two integers performs the arithmetic difference operation whereas subtracting two sets performs the set difference operation. The specific return value of the minus operator is defined in a data … Read more

Python Program to Add Two Numbers

Add Two Integers The most basic Python program to add two integer numbers stored in variables num_1 and num_2 is the expression num_1 + num_2 using the addition operator. The following code shows how to add two numbers 20 and 22 and print the result 42 to the shell: Add Two Integers with User Input … Read more