Programming Articles

Page 458 of 2547

Check if given number is perfect square in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 8K+ Views

A perfect square is a number that can be expressed as the product of an integer with itself. In other words, a number is a perfect square when its square root is an integer. For example, 36 is a perfect square because √36 = 6, and 6 is an integer. In this tutorial, we'll explore different methods to check if a given number is a perfect square in Python. Algorithm To check if a number is a perfect square, we follow these steps ? Calculate the square root of the given number Take the integer ...

Read More

Check if given number is Emirp Number or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

An Emirp number is a prime number that becomes a different prime when its digits are reversed. The term "Emirp" is "prime" spelled backwards. For a number to be Emirp, it must be prime, and its reverse must also be prime (and different from the original). For example, 97 is an Emirp number because 97 is prime, and its reverse 79 is also prime. Algorithm To check if a number is Emirp, we follow these steps ? Check if the number is prime If not prime, return False Calculate the reverse of the number Check ...

Read More

Check if given number is a power of d where d is a power of 2 in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 217 Views

Given a number n and another value d, we need to check whether n is a power of d, where d itself is a power of 2. For example, if n = 32768 and d = 32, the result is True because 32768 = 32³. Algorithm To solve this problem, we follow these steps: First, check if n is a power of 2 using bitwise operations Count how many times we can divide n by 2 to get the power of n as base 2 Count how many times we can divide d by 2 to ...

Read More

How can grid plot in Bokeh library be created with Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 242 Views

Bokeh is a powerful Python library for creating interactive data visualizations that render in web browsers. It converts data into JSON format and uses BokehJS (written in TypeScript) to create interactive plots using HTML and JavaScript. Installation Install Bokeh using pip or conda ? pip install bokeh Or using Anaconda ? conda install bokeh Creating a Grid Plot with Image A grid plot displays data as a 2D image with customizable grid lines. Here's how to create one using mathematical functions ? import numpy as np from ...

Read More

How can Bokeh library be used to visualize twin axes in Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 324 Views

Bokeh is a Python package that helps in data visualization. It is an open source project. Bokeh renders its plot using HTML and JavaScript. This indicates that it is useful while working with web-based dashboards. Matplotlib and Seaborn produce static plots, whereas Bokeh produces interactive plots. This means when the user interacts with these plots, they change accordingly. Plots can be embedded as output of Flask or Django enabled web applications. Jupyter notebook can also be used to render these plots. Installation Installation of Bokeh on Windows command prompt: pip3 install bokeh ...

Read More

Check if given four integers (or sides) make rectangle in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

A rectangle is a quadrilateral with four right angles and two pairs of opposite sides that are equal in length. Given four integers representing sides, we need to check if they can form a rectangle. So, if the input is like sides = [10, 30, 30, 10], then the output will be True as there are two pairs of equal sides (10, 10) and (30, 30). Algorithm To solve this, we will follow these steps − If all four sides are equal, then it's a square (which is also a rectangle), ...

Read More

Check if given array is almost sorted (elements are at-most one position away) in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 485 Views

Suppose we have an array of numbers where all elements are unique. We need to check whether the array is almost sorted or not. An array is almost sorted when any of its elements can occur at a maximum of 1 distance away from its original position in the sorted array. For example, if we have nums = [10, 30, 20, 40], the output will be True because 10 is at its correct position and all other elements are at most one place away from their actual sorted position. Algorithm To solve this problem, we follow these ...

Read More

How can Bokeh be used to visualize multiple bar plots in Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 755 Views

Bokeh is a powerful Python data visualization library that creates interactive plots for web browsers. It converts Python data into JSON format and uses BokehJS (a JavaScript library) to render visualizations. This makes Bokeh particularly useful for creating multiple bar plots that can be displayed in web applications. Installation Install Bokeh using pip or conda ? pip install bokeh Or using Anaconda ? conda install bokeh Creating Multiple Bar Plots To create multiple bar plots side by side, we use the dodge() transform function. This function shifts bars horizontally ...

Read More

How can Bokeh be used to visualize multiple shapes on a plot in Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 255 Views

Bokeh is a Python package that helps in data visualization. It is an open source project. Bokeh renders its plots using HTML and JavaScript, making it ideal for creating interactive web-based dashboards. Unlike Matplotlib and Seaborn that produce static plots, Bokeh creates interactive visualizations that respond to user interactions. Bokeh converts data into JSON format, which is then processed by BokehJS (a JavaScript library written in TypeScript) to render visualizations in modern browsers. Installation Install Bokeh using pip or conda ? pip install bokeh Or using conda ? conda install bokeh Creating Multiple Shapes on a Plot Bokeh ...

Read More

Check if frequency of each digit is less than the digit in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 193 Views

When working with digit frequency validation, we often need to check whether each digit in a number appears no more times than its own value. For example, digit 5 can appear at most 5 times, digit 3 can appear at most 3 times, and so on. So, if the input is like n = 5162569, then the output will be True as the digits and frequencies are (5, 2), (1, 1), (6, 2), (2, 1) and (9, 1). For all digits, the frequency is less than or equal to the digit value. Algorithm To solve this problem, ...

Read More
Showing 4571–4580 of 25,466 articles
« Prev 1 456 457 458 459 460 2547 Next »
Advertisements