Server Side Programming Articles

Page 416 of 2109

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

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 1K+ Views

A Harshad Number (also known as a Niven number) is a positive integer that is divisible by the sum of its digits. For example, 12 is a Harshad number because 12 ÷ (1 + 2) = 12 ÷ 3 = 4, which is a whole number. Basic Approach To check if a number is a Harshad number, we need to ? Calculate the sum of all digits in the number Check if the original number is divisible by this sum Example my_num = 134 remaining = sum_val = 0 print("Checking if", ...

Read More

Python program to print all Happy numbers between 1 and 100

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 827 Views

A happy number is a number that eventually reaches 1 when replaced by the sum of the square of its digits repeatedly. For example, 7 is happy because 7² = 49, then 4² + 9² = 97, then 9² + 7² = 130, and so on until we reach 1. Numbers that don't reach 1 will eventually cycle. The most common cycle includes 4, which is why we check for it as a stopping condition. Algorithm To find happy numbers between 1 and 100 ? For each number, repeatedly calculate the sum of squares of ...

Read More

Python program to print all Disarium numbers between 1 to 100

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 1K+ Views

A Disarium number is a number where the sum of its digits raised to the power of their respective positions equals the original number itself. For example, 89 is a Disarium number because 81 + 92 = 8 + 81 = 89. To find all Disarium numbers between 1 and 100, we need to calculate the length of each number and check if the sum of digits raised to their positional powers equals the original number. Complete Program def length_calculation(my_val): len_val = 0 while(my_val != 0): ...

Read More

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

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 437 Views

A Disarium Number is a number where the sum of its digits raised to the power of their respective positions equals the original number itself. For example, 175 is a Disarium number because 11 + 72 + 53 = 1 + 49 + 125 = 175. Understanding Disarium Numbers To check if a number is a Disarium number, we need to ? Extract each digit from the number Calculate the total number of digits Raise each digit to the power of its position (1-based indexing) Sum all the results and compare with the original number ...

Read More

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

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 604 Views

When it is required to find all numbers that are odd and palindromes within a given range, list comprehension and the modulo operator (%) can be used to achieve this efficiently. A palindrome is a number that reads the same forwards and backwards, such as 121 or 1331. For a number to be both odd and a palindrome, it must satisfy two conditions: divisibility check and string comparison. Syntax result = [x for x in range(start, end+1) if x%2!=0 and str(x)==str(x)[::-1]] Example Here's how to find all odd palindromes in a given range ...

Read More

Python Program to Implement Binomial Tree

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 709 Views

A binomial tree is a data structure used in computer science and financial modeling. It consists of nodes where each tree of order k has 2^k nodes. In Python, we can implement this using object-oriented programming with a class that manages tree creation and combination operations. Binomial Tree Class Implementation Here's how to create a binomial tree class with methods to add children and combine trees ? class BinomialTree: def __init__(self, key): self.key = key self.children ...

Read More

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

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 568 Views

When it is required to split the array and add the first part to the end, we can use list slicing or implement a rotation algorithm. This operation is commonly known as left rotation of an array. A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on). Method 1: Using List Slicing The simplest approach is to use Python's list slicing to split and rearrange the array ? def split_and_rotate(arr, k): """Split array at position k and move ...

Read More

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

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 756 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, and the functions are used to perform operations. Below is a demonstration for the same − Example class get_subset: def sort_list(self, my_list): return self.subset_find([], sorted(my_list)) ...

Read More

Python Program to Create a Class wherein a Method accepts a String from the User and Another Prints it

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 490 Views

When it is required to create a class that has a method to accept a string from the user and another method to print the string, object-oriented programming is used. Here, a class is defined with attributes and methods that perform specific operations on user input. Below is a demonstration for the same − Example class StringHandler: def __init__(self): self.string = "" def get_data(self): self.string = input("Enter ...

Read More

Python Program to Create a class performing Calculator Operations

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 4K+ Views

When it is required to create a class that performs calculator operations, 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 operations. Below is a demonstration for the same − Example class calculator_implementation(): def __init__(self, in_1, in_2): self.a = in_1 self.b = in_2 ...

Read More
Showing 4151–4160 of 21,090 articles
« Prev 1 414 415 416 417 418 2109 Next »
Advertisements