Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Programming Articles
Page 620 of 2547
Python Program to check if two given matrices are identical
Matrix refers to a collection of numbers arranged in rows and columns to form a rectangular array. The numbers make up the matrix's entries, or elements. We need to create a Python function to determine whether two given matrices are identical. In other words, we say that two matrices are identical if all of the elements in their respective places are the same. Identical Matrices Two matrices are only considered equal if and when they meet the requirements listed below − There should be an equal number of rows and columns ...
Read MoreCreate Word Cloud using Python
A word cloud is a visual representation of text data, where the size of each word indicates its frequency or importance within the dataset. It helps us to identify the most common and important words in a text. It is typically used to describe/denote big data in a word. In this article, we will create a word cloud on the Python programming language, and the data is accessed from Wikipedia. Required Modules Following are the modules required to create a word cloud in Python − Install wordcloud Before installing the word cloud module, you have ...
Read MoreHow to convert HTML to PDF using Python
Converting HTML to PDF programmatically is a common requirement for generating reports, invoices, or documentation. Python provides several libraries for this task, with pdfkit being one of the most popular options as it leverages the powerful wkhtmltopdf engine. In this article, we will explore how to convert HTML files to PDF using Python with the pdfkit library. Prerequisites and Installation Step 1: Install pdfkit Library First, install the pdfkit library using pip − pip install pdfkit Step 2: Install wkhtmltopdf The pdfkit library requires wkhtmltopdf as its backend engine. Follow these ...
Read MorePython program to sort a list according to the second element in the sublist.
In this article, we will learn how to sort a list according to the second element in each sublist. This is useful when working with data where each item is a pair, such as name-score pairs or key-value combinations. Let's say we have the following list ? [['jack', 50], ['antony', 20], ['jones', 87], ['gary', 70], ['tom', 90], ['sam', 110], ['warner', 65]] The output should be sorted according to the second element ? [['antony', 20], ['jack', 50], ['warner', 65], ['gary', 70], ['jones', 87], ['tom', 90], ['sam', 110]] Using sort() Method The ...
Read MorePython program to calculate BMI(Body Mass Index) of your Body
Body Mass Index (BMI) is a measure used to determine whether a person has a healthy body weight for their height. The BMI formula is: BMI = weight (kg) / height² (m²). Algorithm Step 1: Input height in meters and weight in kilograms Step 2: Apply the BMI formula: weight / (height × height) Step 3: Display the calculated BMI value Step 4: Interpret the BMI category Basic BMI Calculator Here's a simple program to calculate BMI − height = float(input("Enter your height (m): ")) weight = float(input("Enter your weight (kg): ")) ...
Read MorePython program multiplication of two matrix.
Matrix multiplication is a fundamental operation in linear algebra where we multiply two matrices to produce a resultant matrix. In Python, we can implement matrix multiplication using nested loops and list comprehensions. Algorithm Step 1: Input two matrices of compatible dimensions Step 2: Initialize a result matrix with zeros Step 3: Use three nested loops: - Outer loop for rows of first matrix - Middle loop for columns of second matrix - Inner loop for dot product calculation Step 4: For each position (i, j), multiply ...
Read MorePython program for Modular Exponentiation
Modular exponentiation calculates (baseexponent) % modulo efficiently. This operation is fundamental in cryptography and number theory, involving three integers: base, exponent, and modulo. Syntax # Basic syntax result = (base ** exponent) % modulo # Using pow() function (recommended) result = pow(base, exponent, modulo) Basic Example Let's calculate (25) % 5 step by step ? base = 2 exponent = 5 modulo = 5 # Step by step calculation power_result = base ** exponent print(f"{base}^{exponent} = {power_result}") final_result = power_result % modulo print(f"{power_result} % {modulo} = {final_result}") ...
Read MoreString slicing in Python to rotate a string
String rotation involves moving characters from one end of a string to the other. Python's string slicing makes this operation simple and efficient. We can rotate strings in two directions: left rotation (anticlockwise) and right rotation (clockwise). Understanding String Rotation Given a string and a rotation distance d: Left Rotation: Move first d characters to the end Right Rotation: Move last d characters to the beginning Example Input: string = "pythonprogram" d = 2 Output: Left Rotation: thonprogrampy Right Rotation: ampythonprogr Algorithm ...
Read MorePython program to move spaces to front of string in single traversal
Given a string that has set of words and spaces, our task is to move all spaces to front of string, by traversing the string only once. We will solve this problem quickly in Python using list comprehension. Example Input: string = "python program" Output: string = " pythonprogram" Algorithm The algorithm follows these steps: Input a string with words and spaces Traverse the input string using list comprehension to extract non-space characters Calculate the number of spaces in ...
Read MoreProgram to check if a number is Positive, Negative, Odd, Even, Zero?
In this article, we are going to learn how to check if the number is positive, negative, odd, even, or zero. Identifying and categorizing a number based on its characteristics is a basic operation. A number can fall into multiple categories: Positive: A number is greater than 0. Negative: A number less than 0. Zero: The number that is equal to 0. Even: A number that is divisible by 2. Odd: A number that is not divisible by ...
Read More