Programming Articles - Page 2414 of 3366

Python Program to check whether it is possible to make a divisible by 3 number using all digits in an array

Pavitra
Updated on 26-Sep-2019 12:33:11

298 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven an array input of integers, we need to find whether it’s possible to make an integer using all the digits available in these numbers such that it would be divisible by 3.Here we will generate a function that will take two arguments namely the array of integers and the length of the array.The implementation given below works on the concept from the mental mathematics. Here we observe that a number is divisible by 3 if the sum of the digits are divisible ... Read More

Python program to check if the given string is pangram

Pavitra
Updated on 26-Sep-2019 12:24:23

9K+ Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a string input, we need to generate a Python program to check whether that string is Pangram or not.A pangram is a sentence/ series of words which contains every letter in the English Alphabets collection.Now let’s see how we can solve the problemWe will use a loop that checks whether each character present in the input string belongs to the alphabet set or not which we will declare manually .The implementation of the approach above is given by −Example Live Demoimport string def ... Read More

Python program to check if a given string is number Palindrome

Pavitra
Updated on 26-Sep-2019 12:22:39

7K+ Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a string input, we need to create a python function to check whether it is a palindrome or not.A string is referred to be palindrome if the reverse of the string is identical with string.We can do this by two methods −Reversal by slicingComparison via negative indexingHere we will be learning reversal pf string bu the help of slicing.To reverse a string by th method of slicing specify the following statement −Str[ : : -1 ]Where the start and end parameters are ... Read More

Python Program to check if the given array is Monotonic

Pavitra
Updated on 26-Sep-2019 12:17:17

1K+ Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven an array input Arr containing n integers. We need to check whether the input array is Monotonic in nature or not.An array is said to be monotonic in nature if it is either continuously increasing or continuously decreasing.Mathematically,An array A is continuously increasing if for all i

Python program to check if a string contains all unique characters

Pavitra
Updated on 26-Sep-2019 12:14:14

729 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a sring input, we need to find whether a string contains all unique characters or not.ApproachWe will create an array of boolean values, where the variable flag at the index i indicates that whether character i in the alphabet is contained in the string or not.The second time we encounter this character we can immediately return false as string characters is no longer unique.We can also return false if the string length exceeds the value of number of unique characters presnt in ... Read More

Python Program to Check Armstrong Number

Pavitra
Updated on 26-Sep-2019 12:11:58

2K+ Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven an integer n , we need to check that the given integer is an armstrong number.A positive integer is called an Armstrong number of order n ifabcd... = a^n + b^n + c^n + d^n + …Here we will be discussing the brute-force approach for an armstrong number of 3 digits and hence of order three.To check the armstrong number of order n we need to replace 3 by the corresponding order value in line number 7.Now let’s see the implementation −Example Live ... Read More

Python Program for Sum of squares of first n natural numbers

Pavitra
Updated on 26-Sep-2019 12:04:49

905 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a positive integer N as input . We need to compute the value of 12 + 22 + 32 + ….. + N2.Problem statement:This can be solved by two methodsMultiplication addition arithmeticUsing mathematical formulaApproach 1: Multiplication & Addition ArithmeticHere we run a loop from 1 to n and for each i, 1

Python Program for Smallest K digit number divisible by X

Pavitra
Updated on 26-Sep-2019 12:00:10

464 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementIntegers n and d are given. We need to find the smallest n-digit number divisible by d.Approach1. FirstNow let's we compute MIN : smallest n-digit number (1000...n-times)2. Now, If MIN % X is 0, ans = MIN3. else, ans = (MIN + X) - ((MIN + X) % X))This is because there will be a number in range [MIN...MIN+X] which is divisible by d.Now let’s see the implementation −Example Live Demodef answer(n, d):    # Computing MAX    Min = pow(10, d-1)    if(Min%n ... Read More

Simple interest in Python Program

Pavitra
Updated on 26-Sep-2019 11:56:50

294 Views

In this article, we will learn about the calculation of simple interest in Python 3.x. Or earlier.Simple interestis 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)/100Where, P is the principal amountT is the time andR is the rateFor Example, If P = 1000, R = 1, T = 2Then SI=20.0Now let’s see how we can implement a simple interest calculator in Python.Example Live DemoP = 1000 R = 1 T = 2 # simple interest SI = (P * R ... Read More

Selection Sort in Python Program

Pavitra
Updated on 26-Sep-2019 11:49:07

390 Views

In this article, we will learn about the Selection sort and its implementation in Python 3.x. Or earlier.In 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 sorted.The 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 ... Read More

Advertisements