• Round to 2 decimal places in C++
    25 January

    How to Round a Number to 2 decimal places in C++

    1. Introduction Rounding numbers to a specific number of decimal places is a common requirement in programming. In C++, this task becomes crucial when dealing with floating-point arithmetic, where precision and accuracy are key. This article will explore methods to round a floating-point number to 2 decimal places in C++. We will look at two […]

  • Python get year from date
    23 January

    Get year from Date in Python

    In this post, we will see how to get year from Date in Python. Dates in Python There are no data types for a date in Python. We can store and process them as strings. However, we have the datetime module to work with objects that can store and process date as well as time. […]

  • 22 January

    Replace space with underscore in Python

    Strings are an essential data type in programming. In Python, we can treat strings as an iterable of characters, and can perform a variety of functions and operations on them. Replacing characters in a string is one such operation. Ways to replace space with underscore in Python In this article, we will discuss various methods […]

  • Python copy file to another directory
    17 January

    How to copy file to another directory in Python

    In this article, we will see different ways to copy file to another directory in Python. We can read and write files in Python. We can also work with paths and directories using different libraries. Ways to copy file to another directoy in Python We will discuss different methods to copy file from one destination […]

  • Split String by pipe in java
    15 January

    Split String by pipe(|) in java

    In this post, we will see how to split String by pipe in java. How to split String by pipe in java There are multiple ways to split String by pipe (|) in Java. Using split() method You can use String’s split() method to split String by pipe in java. Let’s say you want to […]

  • In this post, we will see how to generate random number between 1 to 10 in javascript. How to generate random number between 1 and 10 in javascript We can simply Math.random() method to generate random number between 1 and 10 in javascript. `Math.random()` returns a random number between 0(inclusive), and 1(exclusive). That means `Math.random()` returns always number lower than 1. We can use `Math.random()` with `Math.floor()` to generate random integer. Here is generic formula to generate random number in the range. Math.floor(Math.random() * (maximum - minimum + 1)) + minimum In our case, minimum = 1 maximum = 10 so it will be Math.floor(Math.random() * (10 - 1 + 1)) + 1 Math.floor(Math.random() * 10) + 1 So here is the program to generate random number between 1 and 10 in javascript. var randNum = Math.floor(Math.random() * 10) + 1; console.log(randNum) When you run above program, you will get below output: 3 You can obviously get differnt outout as we are generating random number here. Generate 10 random integers in range of 1 to 10 console.log("Generating 10 random integers in range of 1 to 10") for (let i = 0; i < 10; i++) { var randNum = Math.floor(Math.random() * 10) + 1; console.log(randNum) } Generate 10 random integers in range of 1 to 10 7 5 1 10 5 9 7 7 6 2 Generate random number in a range in javascript Here is generic formula to generate random number in a range. function generateRandomInteger(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } // Generate random number between 1 to 10 console.log(generateRandomInteger(1,10)) // Generate random number between 11 to 20 console.log(generateRandomInteger(11,20)) // Generate random number between 21 to 30 console.log(generateRandomInteger(21,30)) 4 17 28 In case, if you don't want to include maximum while generating random numbers, you can use below function. function generateRandomInteger(min, max) { return Math.floor(Math.random() * (max - min)) + min; } That's all about how to generate random number between 1 and 10 in javascript
    15 January

    Generate Random Number Between 1 and 10 in JavaScript

    1. Introduction In JavaScript, generating random numbers is a common task in various applications, such as games, simulations, or as part of algorithms. Our goal is to learn how to generate a random number between 1 and 10, which can be quite handy in many scenarios. The expected output in each case is a single […]

  • Check if variable is String in Python
    13 January

    Check if Variable Is String in Python

    In this post, we will see what is a string in Python and how to check whether a given variable is a string or not. There are many options in Python when it comes to making a choice of selecting a data type and this sometimes creates a need This tutorial focuses on and demonstrates […]

  • Find rows with nan in Pandas
    11 January

    Find rows with nan in Pandas

    In this post, we will see how to find rows with nan in Pandas. What is nan values in Pandas? A pandas DataFrame can contain a large number of rows and columns. Sometimes, a DataFrame may contain NaN values. Such values indicate that something is not legal and is different from Null which means a […]

  • 09 January

    Convert Set to String in Python

    Sets are an unordered collection of elements in Python. It does not contain duplicate elements and can be defined using the set() function in Python. Ways to convert set to string in Python This tutorial will discuss how to convert a set to string and view it as the latter in Python. We can verify […]