The print() method in Python automatically prints in the next line each time. The print() method by default takes the pointer to the next line.Example Live Demofor i in range(5): print(i)Output0 1 2 3 4Modify print() method to print on the same lineThe print method takes an extra parameter end=" " to keep the pointer on the same line.The end parameter can take certain values such as a space or some sign in the double quotes to separate the elements printed in the same line.Syntaxprint("..." , end=" ")Print on same line with space between each elementThe end=” “ is used ... Read More
Tuples in Python are immutable, meaning that once they are created, their contents cannot be changed. However, there are situations when we want to change the existing tuple, in which case we must make a new tuple using only the changed elements from the original tuple. Following is the example of the tuple − s = (4, 5, 6) print(s) print(type(s)) Following is the output of the above code − (4, 5, 6) Tuple is immutable, although you can use the + operator to concatenate several tuples. The old object is still present at this point, and ... Read More
There is a need to generate random numbers when studying a model or behavior of a program for different range of values. Python can generate such random numbers by using the random module. In the below examples we will first see how to generate a single random number and then extend it to generate a list of random numbers.Generating a Single Random NumberThe random() method in random module generates a float number between 0 and 1.Exampleimport random n = random.random() print(n)OutputRunning the above code gives us the following result −0.2112200Generating Number in a RangeThe randint() method generates a integer between ... Read More
Python provides different modules like urllib, requests etc to download files from the web. I am going to use the request library of python to efficiently download files from the URLs.Let’s start a look at step by step procedure to download files using URLs using request library−1. Import moduleimport requests2. Get the link or urlurl = 'https://www.facebook.com/favicon.ico' r = requests.get(url, allow_redirects=True)3. Save the content with name.open('facebook.ico', 'wb').write(r.content)save the file as facebook.ico.Exampleimport requests url = 'https://www.facebook.com/favicon.ico' r = requests.get(url, allow_redirects=True) open('facebook.ico', 'wb').write(r.content)ResultWe can see the file is downloaded(icon) in our current working directory.But we may need to download ... Read More
A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. Any whole number which is greater than 1 and has only two factors that is 1 and the number itself, is called a prime number Let’s say the following is our input − 7 The output should be as follows − Prime Number Check if a number is Prime or not Let us check if a number if a Prime number or not using the for loop − Example # Number to be checked for prime n ... Read More
The Binomial Theorem describes how to expand an expression raised to any finite power. A binomial theorem is a powerful expansion tool that has applications in algebra, probability, and other fields. Assume we have an expression $\mathrm{(x\:+\:y)^n}$and we need to expand the expression, we can do this using the generalised equation of binomial theorem. The binomial theorem defines a binomial expression for two different terms. The general equation of binomial theorem is: $$\mathrm{(a+b)^{n}=^n{C_{r=0}}a^{n-r}b^{0}\:+\:^n{C_{r=1}}a^{n-1}b^{1\:}+\:........\:+\:^n{C_{r=n-1}}a^{1}b^{n-1}+^n{C_{r=n}}a^{0}b^{n}}$$ $$\mathrm{=n_{\sum_{r=0}}^n{C_{r}}a^{n-r}b^{r}}$$ Where we can get the value of $\mathrm{^n{C_{r}}}$ using the formula, $$\mathrm{^n{C_{r}}=\frac{n!}{(n-r)!r!}}$$[0! is always equals to 1] NOTE There ... Read More
The problem states that we need to figure out the number of ways to choose three points with distance between the most distant points less than or equal to L, a positive integer that will be given as an input. In the problem we will be given an array of different points which lies on the x-axis and an integer L greater than 0. The task involves finding the number of sets of three points where the distance between the most distant points is less than or equal to that integer L. NOTE : The set of points ... Read More
The problem includes finding two odd occurring elements in an array where all other elements occur even times in C++. An array is a data structure in C++ which is used to store a list of elements in it of similar data types. We will be given an array of any size greater than or equal to 2 in input. The array will contain integers in it. Every integer in the array will occur even times except two integers which will be occurring odd times in the array. In this problem, we need to find out those two elements ... Read More
The problem states that we must determine the sum of the product of r and the rth binomial coefficient (r*nCr). Positive numbers that are coefficients in the binomial theorem are called binomial coefficients. Both Pascal's triangle and a straightforward formula can be used to determine the binomial coefficients. The formula for binomial coefficient is: $$\mathrm{n_{c_{r}}=\frac{n!}{(n-r)!r!}}$$ NOTE : The value of 0! is always equal to 1. In this equation n and r can be any non-negative integers and r should never be greater than n. The objective at hand in this problem entails computing the ... Read More
Autism and speech delay are two distinct developmental disorders that can affect children from a very young age. Autism, also known as Autism Spectrum Disorder (ASD), is a neurodevelopmental disorder that affects social communication and behavior, while speech delay is a delay in the development of speech and language skills. While there may be some overlap in symptoms between the two, there are also significant differences between autism and speech delay. What is Autism? Autism is a developmental disorder characterized by − Problems with communication; Problems with social interaction; Repetitive behavior; Behavioral restrictions Children with autism have a ... Read More