Found 34494 Articles for Programming

Python program to determine if the given IP Address is Public or Private using ipaddress module

Gireesha Devara
Updated on 29-Aug-2023 14:31:04

970 Views

In computer networking, IP addresses are used to uniquely identify devices connected to a network. IP addresses can be classified as either public or private. Public IP addresses are assigned to devices that are directly connected to the Internet. They are globally routable and can be accessed from anywhere on the Internet.  Private IP addresses, on the other hand, are used within private networks, such as local area networks (LANs) or home networks. These IP addresses are not directly accessible from the Internet. Private IP addresses are defined by certain reserved address ranges specified by the Internet Engineering Task Force ... Read More

Moser-de Bruijn Sequence

Rinish Patidar
Updated on 28-Aug-2023 20:51:30

113 Views

The problem statement includes printing the first N terms of the Moser−de Bruijn Sequence where N will be given in the user input. The Moser−de Bruijn sequence is a sequence consisting of integers which are nothing but the sum of the different powers of 4 i.e. 1, 4, 16, 64 and so on. The first few numbers of the sequence include 0, 1, 4, 5, 16, 17, 20, 21, 64....... The sequence always starts with zero followed by the sum of different powers of 4 such as $\mathrm{4^{0}}$ i.e $\mathrm{4^{1}\:i.e\:4, }$ then sum of $\mathrm{4^{0}\:and\:4^{1}\:i.e\:5}$ and so on. In this ... Read More

Python Program to create an OTP by squaring and concatenating the odd digits of a number

Gireesha Devara
Updated on 29-Aug-2023 14:30:09

137 Views

The task is to create a One-Time Password (OTP) by squaring and concatenating the odd digits of a given number.  Input Output Scenarios Following are the input-output scenarios for creating an OTP by squaring and concatenating the odd digits of a number Input number = 123456789 Output OTP: 19254981 The odd digits in the number are 1, 3, 5, 7, 9. Squaring each of these digits gives us 1, 9, 25, 49, 81. Concatenating these squared digits together gives us the OTP 19254981. Input: 54321 Output: 2591 The odd digits in the input number are 5, 3, and ... Read More

Vantieghems Theorem for Primality Test

Rinish Patidar
Updated on 28-Aug-2023 18:09:42

65 Views

The problem statement includes using Vantieghems theorem for primality test i.e. we will check for a positive number N which will be user input and print if the number is a prime number or not using the Vantieghems theorem. Vantieghem’s Theorem The Vantieghems theorem for primality states that a positive number, N is a prime number if the product of $\mathrm{2^{i}−1}$ where the value of i ranges from 1 to N−1 is congruent to N modulo $\mathrm{2^{N}−1}$ If both the values are congruent then the number N is a prime number else it is not a prime number. Congruent ... Read More

Sum of Range in a Series of First Odd then Even Natural Numbers

Rinish Patidar
Updated on 28-Aug-2023 17:59:41

86 Views

The problem statement includes finding the sum of range in a series of first odd numbers then even natural numbers up to N. The sequence consists of all the odd natural numbers from 1 to N and then all the even natural numbers from 2 to N, including N. The sequence will be of size N. We will be provided with a range in the problem for which we need to find out the sum of the sequence within that range, a and b i.e. [a, b]. Here a and b are included in the range. For example, we are ... Read More

Sum of product of Consecutive Binomial Coefficients

Rinish Patidar
Updated on 28-Aug-2023 17:54:20

131 Views

The problem statement includes printing the sum of product of consecutive binomial coefficients for any positive number, N which will be the user input. The positive coefficients in the binomial expansion of any term are called binomial coefficients. These binomial coefficients can be found out using Pascal's triangle or a direct formula. The formula to calculate the binomial coefficient: $$\mathrm{^nC_{r}=\frac{n!}{(n-r)!r!}}$$ where, n and r can be any positive numbers and r should never be greater than n. Note : The value of 0! is always equal to 1. In this problem, we will be given a positive number N and ... Read More

Python program to create a list centered on zero

Gireesha Devara
Updated on 29-Aug-2023 14:29:15

133 Views

Creating a list centered on zero involves generating a sequence of numbers where zero is positioned in the middle of the list. While the size of the list can be customized, it is often preferred to use an odd number to ensure symmetrical distribution of elements around zero. In this article, we will discuss the different approaches to creating a list centered on zero using Python programming. Approach We can follow the below steps to create a centered list − Determine the desired size of the list. Let's call this value n. If n is an odd number, it ... Read More

Python program to count the number of characters in a String

Gireesha Devara
Updated on 29-Aug-2023 14:27:34

3K+ Views

Strings in Python can contain any sequence of characters, including letters, numbers, symbols, and whitespace. It can represent text, numbers, or any other type of data that can be represented as a sequence of characters. In Python, strings are enclosed in single quotes ('') or double quotes (""). Multiline strings can be created using triple quotes (''' or """). Here are a few examples of valid Python strings: "Hello, World!" "12345" "Python is awesome!" Counting the number of characters in a string involves determining the total count of individual characters within the string. Python offers various techniques for ... Read More

Sum of digits written in different bases from 2 to n-1

Rinish Patidar
Updated on 28-Aug-2023 17:50:33

64 Views

The problem statement includes printing the sum of digits of N, which will be the user input, when written in different bases from 2 to N−1. In this problem, we will be provided any positive integer N and we need to represent that number in a different base numeral system from 2 to N−1 and find the sum of the digit of each different base numeral system. In the base−n numeral system, every digit of the representation of any number in that numeral system from right represents the number of times power of n from 0 to 31. For example, ... Read More

Python program to convert meters in yards and vice versa

Gireesha Devara
Updated on 29-Aug-2023 14:25:59

128 Views

A meter is the fundamental unit of length in the International System of Units (SI) and is used worldwide. It is defined as the length of the path traveled by light in a vacuum during a time interval of 1/299, 792, 458 of a second. Meters are commonly used in scientific, engineering, and everyday contexts. The yard, on the other hand, is a unit of length commonly used in both the British imperial and US customary systems of measurement. It is an English unit defined as 3 feet or 36 inches. It is defined as exactly 0.9144 meters. Yards are ... Read More

Advertisements