Check If a Character in a String is a Letter in Python

SaiKrishna Tavva
Updated on 25-Mar-2025 14:30:20

12K+ Views

In Python, there are several methods to check if a given character in a string is an alphabetic letter. Here, we'll explore three effective techniques: using the isalpha() method, the string module, and regular expressions. Using the isalpha() method The isalpha() method is a built-in method in Python that returns True if all the characters in a string are alphabets (letters) and False otherwise. Example In this example, we have a string "Hello World" and we want to check if the character at index 1 is a letter. We use the isalpha() method to check if the character is ... Read More

Count Maximum Number of Disjoint Pairs in C++

Nishu Kumari
Updated on 24-Mar-2025 15:23:03

111 Views

In this article, we will discuss how to count the maximum number of disjoint pairs in an array, where for each pair (x, y), one element is not less than K times the other. The goal is to find the number of such valid pairs in the array using C++. Given an array of integers, the task is to find all pairs (i, j) such that: arr[i] > K * arr[j] or arr[j] > K * arr[i] holds true for a given constant K. The condition is that no element ... Read More

Count Pairs Whose Bitwise AND Exceeds Bitwise XOR from a Given Array

Nishu Kumari
Updated on 24-Mar-2025 15:22:24

138 Views

In this article, we will learn how to count pairs of numbers from a given array where the bitwise AND of the two numbers is greater than the bitwise XOR. Bitwise operations work on the individual bits of numbers. The AND operation results in 1 only when both bits are 1, while XOR gives 1 when the bits are different. Given an array of integers, we need to count how many pairs (i, j) exist such that the bitwise AND of the pair is greater than the bitwise XOR. In other words, for each pair of elements in the ... Read More

C++ Program for Mirror of Matrix Across Diagonal

Nishu Kumari
Updated on 24-Mar-2025 15:21:04

218 Views

In this article, we will discuss how to create a C++ program to generate the mirror image of a matrix across its diagonal. The diagonal mirror of a matrix means that we swap the elements at symmetric positions with respect to the diagonal. Let's break down the problem step by step and then look at the code that solves this problem. Understanding the Problem For any given matrix, the mirror image across the diagonal means that the element at position (i, j) will be swapped with the element at position (j, i). This operation is also known as transposing ... Read More

Find the Greatest Divisor for Natural Numbers in a Given Range

Nishu Kumari
Updated on 24-Mar-2025 15:20:37

138 Views

In this article, we will explain how to find the greatest divisor that divides all the natural numbers in a given range [L, R]. The task is to identify the largest number that can divide every number between L and R, including both L and R. For example, in the range [6, 9] (which includes 6, 7, 8, and 9), the GCD is 1 because no number greater than 1 divides all of them. Now, let's go through the steps to solve this problem. Approach to Solve the Problem To solve this problem, we can follow these steps: ... Read More

Find Percentage of a Number in PHP

AYUSH MISHRA
Updated on 24-Mar-2025 14:12:01

4K+ Views

In this problem, we are given a number and a percentage value, and we have to find the percentage of the given number. In this article, we are going to learn how we can calculate the percentage of a number in PHP using different approaches. Example 1 The percentage of 300 with respect to 40% is calculated as (300 × 40) / 100 = 120. Input number=300; percentage = 40; Output 120 Example 2 The percentage of 300 with respect to 40% is calculated as (400 × 15) / 100 = 60. Input number=400; percentage = 15; Output 60 ... Read More

Calculate Simple Interest and Compound Interest in PHP

AYUSH MISHRA
Updated on 24-Mar-2025 14:06:01

4K+ Views

What is Simple Interest and Compound Interest? Simple Interest is the interest that depends only on the principal amount taken while compound interest is compounded, i.e., previous interest is added in the current time period. In this article, we are going to learn how to calculate simple interest and compound interest using PHP, as this PHP tutorial is important for beginners. The formula for Calculating Simple Interest is: Simple Interest (SI) = P × R × T / 100 Where: P is the principal amount. R is the interest rate. ... Read More

Difference Between Continue and Break Statements in Java

Alshifa Hasnain
Updated on 21-Mar-2025 19:08:32

9K+ Views

As we know in programming execution of code is done line by line. Now in order to alter this flow Java provides two statements break and continue which are mainly used to skip some specific code at specific lines. Difference Table Following are the important differences between continue and break − Sr. No. Key ... Read More

Sorting Strings with Decimal Points in C++

AYUSH MISHRA
Updated on 21-Mar-2025 19:01:25

2K+ Views

A string containing decimal points is sorted to solve complex programming problems. This question was asked in the Accenture coding assessment in 2025. In C++, there are different ways to sort such strings efficiently. In this article, we are going to discuss various approaches to sorting strings that contain decimal points using C++. How to Sort Strings with Decimal Points? In this problem, we are given an array of strings, where each string represents a decimal number. The goal is to sort these strings in increasing numerical order while ensuring the correct handling of decimal values. Example 1 ... Read More

Sort Array of Binary Values in C++

AYUSH MISHRA
Updated on 21-Mar-2025 19:00:54

363 Views

Sorting an array of binary values (0s and 1s) is a common problem in programming. In C++, there are multiple ways to efficiently sort an array containing only 0s and 1s. In this article, we are going to learn various approaches to sorting an array of binary values using C++. How to Sort an Array of Binary Values? In this problem, we are given an array that consists of only 0s and 1s. The task is to sort the array in ascending order, which means all 0s should come before all 1s. Example 1 ... Read More

Advertisements