Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 300 of 377

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 1K+ 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, if the input is like n = 10, then the output will be1    1    1    1 2    2    2   10 3    3    3   11 4    4    4  100 5    5    5  101 6    6    6 ...

Read More

Python program to print design door mat texture using characters

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 672 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 (|) and the text at middle.So, if the input is like n = 5 m = 15, then the output will be------.|.------ ---.|..|..|.--- ----WELCOME---- ---.|..|..|.--- ------.|.------To solve this, we will follow these steps −for i in range 1 to n-1, increase by 2, doprint(integer of ((m-i*3)/2) number of '-', then ...

Read More

Python program to wrap a text into paragraph with width w

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 1K+ 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 quick brown fox jumps over the lazy dog" w = 9, then the output will beThe quickbrown foxjumpsover thelazy dogTo solve this, we will follow these steps −take the string into stake width into wcall textwrap.fill(s, w) by passing s as the first argument, and w as the second argumentExampleLet ...

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 2K+ 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 will be    *    * *   * * *  * * * * * * * * *  * * * * * * * * * *To solve this, we will follow these steps −for i in range ...

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 161 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 will follow these steps −arr := an array of size 3 and fill with Falsefor each character c in s, doif c is alphanumeric, thenarr[0] := Trueif c is in lowercase, thenarr[1] := Trueif c is in uppercase, thenarr[2] := Truereturn true when all items of arr are trueExampleLet us ...

Read More

Python program to change character of a string using given index

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 448 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 not support item assignment]So, if the input is like s = "python", i = 3, c = 'P', then the output will be "pytPon"To solve this, we will follow these steps −left := s[from index 0 to i]right := s[from index i+1 to end]return left concatenate c concatenate rightExampleLet us ...

Read More

Python program to split a string and join with comma

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 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, Easy, FunnyTo solve this, we will follow these steps −words := a list of words by applying split function on s with delimiter " " blank space.ret := join each items present in words and place ", " in between each pair of wordsreturn retExampleLet us see the following implementation ...

Read More

Python program to find hash from a given tuple

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 6K+ Views

Suppose we have a tuple. There are few numbers are present. We have to find the hash value of this tuple by using hash() function. This is a built-in function. The hash() function can work on some datatypes like int, float, string, tuples etc, but some types like lists are not hashable. As lists are mutable in nature, we cannot hash it. This hash value is used to map other values when we use dictionary.So, if the input is like t = (2, 4, 5, 6, 7, 8), then the output will be -1970127882925375109To solve this, we will follow these ...

Read More

Python program to sort and reverse a given list

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 1K+ Views

Suppose we have a list of numbers in Python. We have to reverse and sort the lists using list operations but do not change the actual list. To reverse the list we have reverse() function for lists but if we use it, the list will be reversed in place. Similar for the sort() also. To maintain actual order we will use the reversed() function and sorted() function.So, if the input is like l = [2, 5, 8, 6, 3, 4, 7, 9], then the output will be [9, 7, 4, 3, 6, 8, 5, 2] [2, 3, 4, 5, 6, ...

Read More

Python program to find average score of each students from dictionary of scores

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 9K+ Views

Suppose we have a dictionary of students marks. The keys are names and the marks are list of numbers. We have to find the average of each students.So, if the input is like scores = {'Amal' : [25, 36, 47, 45], 'Bimal' : [85, 74, 69, 47], 'Tarun' : [65, 35, 87, 14], 'Akash' : [74, 12, 36, 75]}, then the output will be [38.25, 68.75, 50.25, 49.25] so 38.25 is average score for Amal, 68.75 is average score for Bimal and so on.To solve this, we will follow these steps −avg_scores := a new mapfor each name in scores ...

Read More
Showing 2991–3000 of 3,768 articles
« Prev 1 298 299 300 301 302 377 Next »
Advertisements