Found 33676 Articles for Programming

Hoax Number

Rinish Patidar
Updated on 28-Aug-2023 15:28:20

336 Views

The problem statement includes checking if the given number N, which will be the user input, is a hoax number or not. A Hoax number is a composite number whose sum of digits of its distinct prime factors is equal to the sum of the digits of the composite number itself. Since 1 is not a prime number, we don’t consider 1 as a sum of digits of distinct prime numbers. If a prime number is a factor of the composite number more than once, it is just considered once while taking the sum of digits of prime factors. In ... Read More

Python Program To Convert dictionary values to Strings

Gireesha Devara
Updated on 29-Aug-2023 14:19:41

833 Views

A dictionary in Python is an unordered collection of key-value pairs. It is a data structure that allows you to store and retrieve values based on a unique key associated with each value. Keys in a dictionary are used to uniquely identify values, and they must be immutable, such as strings, numbers, or tuples. On the other hand, the associated values in a dictionary can be of any data type and can be mutable. When we want to convert a dictionary values to strings, we need to iterate over the dictionary using a loop and convert each value to a ... Read More

Hardy-Ramanujan Theorem

Rinish Patidar
Updated on 28-Aug-2023 15:27:05

263 Views

The Hardy−Ramanujan Theorem states that the number of distinct prime factors of any natural number N will be approximately equal to the value of $\mathrm{\log(\log N)}$ for most of the cases. For example, let’s consider N to be 1000. The number of distinct prime factors of 15 are 2 and 5 i.e. 2 distinct prime factors. The value of $\mathrm{\log_{e}(\log_{e}(1000))}$ is equal to 1.932 which is approximately equal to 2. The Hardy−Ramanujan theorem is proved in the above case. Since the theorem states that the number of distinct prime factors will be approximately equal to $\mathrm{\log(\log(N))}$ for most of ... Read More

Python Program to convert Dictionary to List by Repeating keys corresponding value times

Gireesha Devara
Updated on 29-Aug-2023 14:10:32

150 Views

In Python, dictionaries are key-value pairs where each key is associated with a corresponding value. When we want to convert a dictionary to a list by repeating keys, we need to iterate over each key-value pair and repeat the key based on its corresponding value. Input Output Scenarios See the following input-output scenarios to understand the concept of converting a dictionary to a list by repeating keys corresponding to the number present in the values. Input dictionary: {'a': 3, 'b': 2, 'c': 1} Output list: ['a', 'a', 'a', 'b', 'b', 'c'] In the input dictionary the key 'a' has ... Read More

Python program to convert Dict of list to CSV

Gireesha Devara
Updated on 29-Aug-2023 14:07:37

2K+ Views

In a dictionary, keys must be unique and immutable, while values can be of any type and can have a list of values. In the case of a dictionary of lists, each key points to a list that can contain multiple elements.  Here's an example of a dictionary of lists − data = {'numbers':[1, 2, 3, 4, 5, 6], 'states':['UP', 'Tamil Nadu', 'Telangana', 'Gujarat', 'UP', 'Tamil Nadu'], 'cities':['Agra', 'Chennai', 'Hyderabad', 'Surat', 'Lucknow', 'Coimbatore']}) In the above dictionary, each key is mapped to a list of values. For instance, the 'states' key maps to the list ['UP', 'Tamil Nadu', 'Telangana', ... Read More

Given a Number N in Decimal Base, find Number of its Digits in any Base (base b)

Rinish Patidar
Updated on 28-Aug-2023 15:25:51

358 Views

The problem statement includes finding the number of digits in N when represented in any base b numeral system. Initially, N is given in the base−10 numeral system. In the problem, we will be provided with a positive integer N in the input which will be in the base−10 numeral system and a positive integer b greater than 1. Our task will be to find the number of digits when N is being represented in the base−b numeral system. Any number represented in any base number, every digit from right represents the number of times power of that base number ... Read More

Count Numbers formed by given two Digit with Sum having given Digits

Rinish Patidar
Updated on 28-Aug-2023 15:23:19

181 Views

The problem statement includes counting the numbers formed by the given two digits, x and y of size N with sum having given digits only i.e. x and y. We need to count the distinct numbers which can be formed by the digits, x and y which will be the user input of size N where N ranges from 1 to 10^6. The N will also be provided in the input. The numbers formed using the digits, x and y of size N must be such that the sum of digits of the numbers formed should have only digits ... Read More

Finding the Maximum and Minimum in a Python set

Dr Ruqaiya Khanam
Updated on 28-Aug-2023 14:45:55

9K+ Views

In this article, the user will see how to calculate the maximum and minimum in a set using Python language. The main feature of the python set is that it contains no duplicates elements, store the elements in unordered form and is also difficult to alter the elements presented in the set. In this article, three different methods are illustrated that is Converting the set to a list, using built-in functions, and using the sorted() function. The ‘sorted()’ function retrieves a set’s element in a sorted way. Approach 1: Finding the maximum and minimum in a Python set ... Read More

Python program to find volume, surface area and space diagonal of a cuboid

Dr Ruqaiya Khanam
Updated on 28-Aug-2023 14:44:16

4K+ Views

In this article, we will discuss how to compute the volume, surface area, and space diagonal of a cuboid. A Cuboid is a 3D geometric shape that resembles a rectangular box. It is also called a rectangular prism. A cuboid has six rectangular faces with twelve edges. The length, breadth, and height of a cuboid are different, but in the case of a cube, all sides are equal. Two examples are illustrated in this article. The first example uses the concept of a user-defined function and the second example uses the parameterized constructor of a defined class to calculate the ... Read More

Python Program to get all Possible Slices of a String for K Number of Slices

Dr Ruqaiya Khanam
Updated on 28-Aug-2023 14:34:08

120 Views

In this article, the user will understand how to get all possible slices of a string for K number of slices in a Python program. Two different examples are depicted in this article. We will employ an iteration approach to accomplish the desired result. In the second example, we will utilize the itertools.combinations approach to obtain the sliced string. Let's take an example to demonstrate the computation. The following examples are provided for understanding purposes, and we will go through the computation process one by one. Example 1: Finding all possible slices of a string for K number of slices ... Read More

Advertisements