Arnab Chakraborty has Published 4452 Articles

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

Arnab Chakraborty

Arnab Chakraborty

Updated on 11-Oct-2021 11:22:04

231 Views

Suppose we have two values k and n. Consider a random permutation say p1, p2, ..., pn of first n natural numbers numbers 1, 2, ..., n and calculate the value F, such that F = (X2+...+Xn-1)k, where Xi is an indicator random variable, which is 1 when one of ... Read More

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

Arnab Chakraborty

Arnab Chakraborty

Updated on 11-Oct-2021 11:21:48

897 Views

Suppose we have a value n. We have to print Decimal, Octal, Hexadecimal and Binary equivalent of first n numbers (1 to n) in four different columns. As we know, we can express the numbers with prefix characters d, o, X and b for decimal, octal, hexadecimal and decimal respectively.So, ... Read More

Python program to print design door mat texture using characters

Arnab Chakraborty

Arnab Chakraborty

Updated on 11-Oct-2021 11:16:15

454 Views

Suppose we have two numbers n and m, m will be multiple of n. We have to draw a door mat pattern with a word say "WELCOME" in the middle. The mat size will be n x m. We have to make this mat using dots(.), hyphens (-), pipe symbols ... Read More

Python program to wrap a text into paragraph with width w

Arnab Chakraborty

Arnab Chakraborty

Updated on 11-Oct-2021 11:11:31

722 Views

Suppose we have a string s and width w. We have to wrap this text into a paragraph with width w. This can be done very easily with fill() function present inside textwrap library. So we have to import textwrap library first.So, if the input is like s = "The ... Read More

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

Arnab Chakraborty

Arnab Chakraborty

Updated on 11-Oct-2021 11:07:52

1K+ Views

Suppose we have a number n. We have to draw a diamond pattern with asterisks with 2n-1 lines. First 1 to n lines contain 1 to n number of asterisks, and next they are decreasing from n-1 to 1.So, if the input is like n = 5, then the output ... Read More

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

Arnab Chakraborty

Arnab Chakraborty

Updated on 11-Oct-2021 11:01:37

74 Views

Suppose we have a string s. We have to check whether the string contains the following or not.NumbersLowercase lettersUppercase lettersNote − There may be some other symbols, but these three must be thereSo, if the input is like s = "p25KDs", then the output will be TrueTo solve this, we ... Read More

Python program to count number of substring present in string

Arnab Chakraborty

Arnab Chakraborty

Updated on 11-Oct-2021 10:58:07

571 Views

Suppose we have a string s and a substring t. We have to count how many times t occurs in s.So, if the input is like s = "abaabcaabababaab", t = "aab", then the output will be 3 because the substrings are ab(aab)c(aab)abab(aab).To solve this, we will follow these steps ... Read More

Python program to change character of a string using given index

Arnab Chakraborty

Arnab Chakraborty

Updated on 11-Oct-2021 10:55:39

305 Views

Suppose we have a string s, an index i and a character c. We have to replace the ith character of s using c. Now in Python, strings are immutable in nature. We cannot write a statement like s[i] = c, it will raise an error [TypeError: 'str' object does ... Read More

Python program to split a string and join with comma

Arnab Chakraborty

Arnab Chakraborty

Updated on 11-Oct-2021 10:31:58

1K+ Views

Suppose we have few words that are separated by spaces. We have to split these words to form a list, then join them into a string by placing comma in-between.So, if the input is like s = "Programming Python Language Easy Funny", then the output will be Programming, Python, Language, ... Read More

Python program to swap case of English word

Arnab Chakraborty

Arnab Chakraborty

Updated on 11-Oct-2021 10:29:28

233 Views

Suppose we have a string with English letters. We have to swap the case of the letters. So uppercase will be converted to lower and lowercase converted to upper.So, if the input is like s = "PrograMMinG", then the output will be pROGRAmmINgTo solve this, we will follow these steps ... Read More

Advertisements