Found 26504 Articles for Server Side Programming

Python program to print all Disarium numbers between 1 to 100

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 is considered as a disarium number.A Disarium number is the one where the sum of its digits to the power of their respective position is equal to the original number itself.Below is a demonstration for the same −Example Live Demodef 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
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 power of their respective position is equal to the original number itself.Below is a demonstration for the same −Example Live Demodef length_calculation(num_val):    length = 0    while(num_val != 0):       length = length + 1       num_val = num_val//10    return length my_num = 192 remaining ... Read More

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

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):       sum_val = sum_val + (my_num % 10)       my_num = my_num//10    return sum_val my_num = 12345671 print("The number is : ") print(my_num) print("The method to calculate sum of digits is being called...") print("The sum of " +str(my_num) + " is : ") print(sum_of_digits(my_num))OutputThe number ... Read More

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

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 same when they are read in either way- left to right and right to left.Below is a demonstration for the same −Example Live Demomy_list = [] lower_limit = 5 upper_limit = 189 print("The lower limit is : ") print(lower_limit) print("The upper limit is : ") print(upper_limit) my_list = [x for x ... Read More

Python Program to Implement Binomial Tree

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

641 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 operations.Below is a demonstration for the same −Example Live Democlass binomial_tree:    def __init__(self, key):       self.key = key       self.children = []       self.order = 0    def add_at_end(self, t):       self.children.append(t)       self.order = self.order + 1 my_tree = ... Read More

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

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, and so on).Below is a demonstration for the same −Example Live Demodef split_list(my_list, n_val, k_val):    for i in range(0, k_val):       first_val = my_list[0]       for k in range(0, n_val-1):          my_list[k] = my_list[k + 1]       my_list[n_val-1] = first_val my_list ... Read More

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

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, and the functions are used to perform calculator operations.Below is a demonstration for the same −Example Live Democlass get_subset:    def sort_list(self, my_list):       return self. subset_find([], sorted(my_list))    def subset_find(self, curr, my_list):       if my_list:          return self. subset_find(curr, my_list[1:]) + self. subset_find(curr ... Read More

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

AmitDiwan
Updated on 12-Mar-2021 11:54:06

426 Views

When it is required to create a class that has a method that accepts a string from the user, and another method that prints the string, 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 Live Democlass print_it():    def __init__(self):       self.string = ""    def get_data(self):       self.string=input("Enter the string : ")    def put_data(self):     ... Read More

Python Program to Create a class performing Calculator Operations

AmitDiwan
Updated on 12-Mar-2021 11:50:52

3K+ 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 Live Democlass calculator_implementation():    def __init__(self, in_1, in_2):       self.a=in_1       self.b=in_2    def add_vals(self):       return self.a+self.b    def multiply_vals(self):       return self.a*self.b    def divide_vals(self):       return self.a/self.b    def ... Read More

Find n-th node in Postorder traversal of a Binary Tree in C++

sudhir sharma
Updated on 12-Mar-2021 08:33:38

166 Views

In this problem, we are given a binary tree and an integer N. The task is to find the n-th node in Postorder traversal of a Binary Tree.A binary tree has a special condition that each node can have a maximum of two children.Traversal is a process to visit all the nodes of a tree and may print their values too.Let’s take an example to understand the problem, InputN = 6Output3ExplanationPost order traversal of tree − 4, 5, 2, 6, 7, 3, 1Solution ApproachThe idea is to use the post order traversal of the binary tree which is done by ... Read More

Advertisements