Pavitra

Pavitra

123 Articles Published

Articles by Pavitra

Page 8 of 13

Python Program for Product of unique prime factors of a number

Pavitra
Pavitra
Updated on 11-Mar-2026 1K+ Views

In this article, we will learn about the solution to the problem statement given below −Problem statement − Given a number n, we need to find the product of all of its unique prime factors available and return it.For example, Input: num = 11 Output: Product is 11 Explanation: Here, the input number is 11 having only 1 prime factor and it is 11. And hence their product is 11.Approach 1Using a for loop from i = 2 to n+1 check whether i is a factor of n & then check if i is the prime number itself, if yes ...

Read More

Python Program for Selection Sort

Pavitra
Pavitra
Updated on 11-Mar-2026 2K+ Views

In this article, we will learn about the Selection sort and its implementation in Python 3.x. Or earlier.In the selection sort algorithm, an array is sorted by recursively finding the minimum element from the unsorted part and inserting it at the beginning. Two subarrays are formed during the execution of Selection sort on a given array.The subarray, which is already sortedThe subarray, which is unsorted.During every iteration of selection sort, the minimum element from the unsorted subarray is popped and inserted into the sorted subarray.Let’s see the visual representation of the algorithm −Now let’s see the implementation of the algorithm ...

Read More

Python Program for simple interest

Pavitra
Pavitra
Updated on 11-Mar-2026 2K+ Views

In this article, we will learn about the calculation of simple interest in Python 3.x. Or earlier.Simple interest is calculated by multiplying the daily interest rate by the principal amount by the number of days that elapse between the payments.Mathematically, Simple Interest = (P x T x R)/100 Where, P is the principal amount T is the time and R is the rateFor example, If P = 1000, R = 1, T = 2 Then SI=20.0 Now let’s see how we can implement a simple interest calculator in Python.ExampleP = 1000 R = 1 T = 2 # simple interest ...

Read More

Python program to convert decimal to binary number

Pavitra
Pavitra
Updated on 11-Mar-2026 1K+ Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a number we need to convert into a binary number.Approach 1 − Recursive SolutionDecToBin(num):    if num > 1:       DecToBin(num // 2)       print num % 2Exampledef DecimalToBinary(num):    if num > 1:       DecimalToBinary(num // 2)    print(num % 2, end = '') # main if __name__ == '__main__':    dec_val = 35    DecimalToBinary(dec_val)Output100011All the variables and functions are declared in the global scope as shown below −Approach 2 − Built-in SolutionExampledef decimalToBinary(n): ...

Read More

Python program to find largest number in a list

Pavitra
Pavitra
Updated on 11-Mar-2026 413 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven list input, we need to find the largest numbers in the given list .Here we will discuss two approachesUsing sorting techniquesUsing built-in max() functionApproach 1 − Using built-in sort() functionExamplelist1 = [18, 65, 78, 89, 90] list1.sort() # main print("Largest element is:", list1[-1])OutputLargest element is: 90Approach 2 − Using built-in max() functionExamplelist1 = [18, 65, 78, 89, 90] # main print("Largest element is:",max(list1))OutputLargest element is: 90ConclusionIn this article, we learnt about the approach to find largest number in a list.

Read More

Python program to find sum of absolute difference between all pairs in a list

Pavitra
Pavitra
Updated on 11-Mar-2026 435 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a list input , we need to find the sum of absolute difference between all pairs in a list.Enumerate() method adds a counter to an iterable and returns it in a form of enumerate object type.In this method, we have a list ‘diffs’ which contains the absolute difference.We use two loops having two variables initialized . One is to iterate through the counter and another for the list element. In every iteration, we check whether the elements are similar or not.If not, ...

Read More

Python program to find the highest 3 values in a dictionary

Pavitra
Pavitra
Updated on 11-Mar-2026 3K+ Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a dictionary, we need to find the three highest valued values and display them.Approach 1 − Using the collections module ( Counter function )Examplefrom collections import Counter # Initial Dictionary my_dict = {'t': 3, 'u': 4, 't': 6, 'o': 5, 'r': 21} k = Counter(my_dict) # Finding 3 highest values high = k.most_common(3) print("Dictionary with 3 highest values:") print("Keys: Values") for i in high:    print(i[0], " :", i[1], " ")OutputDictionary with 3 highest values: Keys: Values r : 21 t : ...

Read More

Using Counter() in Python 3.x. to find minimum character removal to make two strings anagram

Pavitra
Pavitra
Updated on 11-Mar-2026 253 Views

In this article, we will learn about how we can make a string into a pangram using the counter() function in Python 3.x. Or earlier. To do so we are allowed to remove any character from the input string. We will also find the number of such required characters to be removed to make the string into an anagram.Two strings are said to be anagrams of each other when they contain the same type of alphabets in any random order.The counter () method is present in the collection module available in Python. The prerequisite is to import the collections module ...

Read More

What makes Python Cool?

Pavitra
Pavitra
Updated on 11-Mar-2026 299 Views

In this article, we will learn about what all features makes python cool and different from other languages.>>>import thisOutputThe Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. The flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to ...

Read More

Implement IsNumber() function in Python

Pavitra
Pavitra
Updated on 11-Mar-2026 234 Views

In this article, we will about the implement isNumber() method using Python 3.x. Or earlier.This method takes in a string type as input and returns boolean True or False according to whether the entered string is a number or not. To do this we take the help of exception handling by using try and except statement.ExampleLet’s look at some example −# Implementation of isNumber() function def isNumber(s):    if(s[0] =='-'):       s=s[1:]    #exception handling    try:       n = int(s)       return True    # catch exception if any error is encountered   ...

Read More
Showing 71–80 of 123 articles
« Prev 1 6 7 8 9 10 13 Next »
Advertisements