AmitDiwan has Published 10744 Articles

Python Program for Reversal algorithm for array rotation

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 12:16:54

347 Views

When it is required to reverse a rotated array, a method is defined, that iterates through the list and reverse the list. Another method is defined, that rotates the list, and another method is defined that displays the list. A simple loop and indexing is used to achieve this.Below is ... Read More

Python program to determine whether the given number is a Harshad Number

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 12:15:06

1K+ Views

When it is required to determine if a given number is a Harshad number or not, a simple loop and ‘%’ operator, ‘+’ operator and ‘//’ operators can be used.A Harshad number is also known as a Niven number. It is a number whoses base is an integer that can ... Read More

Python program to print all Happy numbers between 1 and 100

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 12:13:33

745 Views

When it is required to print all the ahppy numbers between 1 and 100, a simple loop and operations like ‘%’, ‘+’, and ‘//’ are used.A happy number is the one that ends up as 1, when it is replaced by the sum of square of every digit in the ... Read More

Python program to print all Disarium numbers between 1 to 100

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 12:09:50

1K+ Views

When it is required to print all the disarium numbers between 1 and 100, a simple loop can be run between 1 and 100 and the length of every number can be calculated, and the power of the position can be multipled with the number itself.If they are equal, it ... Read More

Python program to check if the given number is a Disarium Number

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 12:06:35

366 Views

When it is required to check if a given nmber is a disarium number, the sum of digits powered to their respective position is computed. Before this, the number of digits present in the number is determined.A Disarium Number is the one where the sum of its digits to the ... Read More

Python Program to Find the Sum of Digits in a Number without Recursion

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 12:04:56

781 Views

When it is required to find the sum of digits in a number without using the method of recursion, the ‘%’ operator, the ‘+’ operator and the ‘//’ operator can be used.Below is a demonstration for the same −Example Live Demodef sum_of_digits(my_num):    sum_val = 0    while (my_num != 0): ... Read More

Python Program to Find All Numbers which are Odd and Palindromes Between a Range of Numbers

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 12:03:02

549 Views

When it is required to find all the numbers that are odd, and are palindromes and lie between a given range of values, and it has been told that recursion can’t be used, then, list comprehension, and ‘%’ operator can be used to achieve the same.Palindromes are string that are ... Read More

Python Program to Implement Binomial Tree

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 12:02:05

640 Views

When it is required to implement a binomial tree in Python, object oriented method is used. Here, a class is defined, and attributes are defined. Functions are defined within the class that perform certain operations. An instance of the class is created, and the functions are used to perform calculator ... Read More

Python Program to Split the array and add the first part to the end

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 11:57:55

503 Views

When it is required to split the list, and then add this first part to the end of the list, a simple iteration through the list and list slicing is required.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, ... Read More

Python Program to Create a Class and Get All Possible Subsets from a Set of Distinct Integers

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 11:56:16

691 Views

When it is required to create a class to get all the possible subsets of integers from a list, object oriented method is used. Here, a class is defined, and attributes are defined. Functions are defined within the class that perform certain operations. An instance of the class is created, ... Read More

Advertisements