Programming Articles

Page 123 of 2547

Python program to capitalize each word\'s first letter

Akshitha Mote
Akshitha Mote
Updated on 26-Mar-2026 2K+ Views

Let's understand the problem statement: we need to convert a given string to a title case, which involves capitalizing the first letter of each word while converting the remaining letters to lowercase. The following are the various ways to capitalize each word's first letter in a string ? Using title() method Using capitalize() method Using upper() method Importing string module Importing regex module Capitalizing a String in a File Using the title() ...

Read More

Python program to print rangoli pattern using alphabets

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 5K+ Views

A rangoli pattern is a diamond-shaped pattern that uses alphabets arranged symmetrically. Given a number n, we create an alphabet rangoli of size n where alphabets start from 'a' and go up to the nth letter of the alphabet. Understanding the Pattern For n = 5, the rangoli pattern looks like this: --------e-------- ------e-d-e------ ----e-d-c-d-e---- --e-d-c-b-c-d-e-- e-d-c-b-a-b-c-d-e --e-d-c-b-c-d-e-- ----e-d-c-d-e---- ------e-d-e------ --------e-------- The pattern has the following characteristics: Each row is symmetric with dashes for spacing The middle row contains all alphabets from 'a' to the nth letter Upper and lower halves mirror ...

Read More

Python program to print decimal octal hex and binary of first n numbers

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

Sometimes we need to display numbers in different formats: decimal, octal, hexadecimal, and binary. Python provides format specifiers to convert numbers into these representations with proper alignment. So, if the input is like n = 10, then the output will be ? 1 1 1 1 2 2 2 10 3 3 3 11 4 4 4 100 5 5 5 101 6 6 ...

Read More

Python program to print design door mat texture using characters

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 693 Views

A door mat pattern is a decorative text design that creates a symmetric mat-like structure. In this pattern, we use hyphens (-), dots (.), and pipe symbols (|) to create a design with "WELCOME" in the center. The mat has dimensions n × m, where m is a multiple of n. Understanding the Pattern The door mat follows this structure: Top half: Expanding pattern from 1 to n-1 (odd numbers only) Middle: "WELCOME" text surrounded by hyphens Bottom half: Mirror of the top half in reverse order Each row contains: Left padding of ...

Read More

Python program to wrap a text into paragraph with width w

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

Text wrapping is a common task when formatting output for display or printing. Python's textwrap module provides the fill() function to wrap text into paragraphs with a specified width. Syntax textwrap.fill(text, width=70, **kwargs) Parameters The fill() function accepts the following parameters: text − The string to be wrapped width − Maximum line width (default is 70) break_long_words − Break words longer than width (default True) break_on_hyphens − Break on hyphens (default True) Basic Text Wrapping Let's wrap a text string with width 9 ? import textwrap ...

Read More

Python program to show diamond pattern with 2n-1 lines

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 2K+ Views

A diamond pattern is a symmetric arrangement of asterisks that expands from one star to n stars, then contracts back to one star. The pattern consists of 2n-1 lines total, with the widest part containing n asterisks. Understanding the Pattern For n = 5, the diamond pattern looks like ? * * * * * * * * * * * * * * * * * * * * * * * * * ...

Read More

Python program to validate string has few selected type of characters or not

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 165 Views

When working with strings in Python, you may need to validate whether a string contains specific types of characters. This article demonstrates how to check if a string contains numbers, lowercase letters, and uppercase letters. Problem Statement Given a string, we need to check whether it contains all three of the following character types ? Numbers (digits) Lowercase letters Uppercase letters Note: The string may contain other symbols, but all three character types above must be present. For example, if the input string is "p25KDs", the output should be True because it contains ...

Read More

Python Program to calculate function from indicator random variable from given condition

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 361 Views

This problem involves calculating the expected value of a function from indicator random variables based on local extrema in random permutations. Given values k and n, we work with a random permutation of first n natural numbers and calculate F = (X₂+...+Xₙ₋₁)ᵏ, where Xᵢ is 1 when pᵢ₋₁ < pᵢ > pᵢ₊₁ or pᵢ₋₁ > pᵢ < pᵢ₊₁ (local maximum or minimum), and 0 otherwise. Understanding the Problem The indicator random variable Xᵢ equals 1 when position i is a local extremum (peak or valley) in the permutation. The expected value calculation uses precomputed formulas for different values ...

Read More

Python program to change character of a string using given index

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 479 Views

Strings in Python are immutable, meaning you cannot modify individual characters directly. When you need to change a character at a specific index, you must create a new string using slicing and concatenation. For example, if we have s = "python", i = 3, and c = 'P', attempting s[i] = c will raise a TypeError: 'str' object does not support item assignment. Algorithm To replace a character at index i with character c ? Extract the left part: s[0:i] Extract the right part: s[i+1:] Concatenate: left + c + right Using String ...

Read More

Python program to split a string and join with comma

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

Sometimes we need to split a string into individual words and then join them back together with commas instead of spaces. Python provides simple built-in methods to accomplish this task efficiently. So, if the input is like s = "Programming Python Language Easy Funny", then the output will be Programming, Python, Language, Easy, Funny Algorithm To solve this, we will follow these steps − words − Create a list of words by applying split() function on the string with delimiter " " (space) result − Join each ...

Read More
Showing 1221–1230 of 25,469 articles
« Prev 1 121 122 123 124 125 2547 Next »
Advertisements