code-rag-bench/online-tutorials huggingface dataset:
Swift - Decision Making

Decision making structures require that the programmer specifies one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.
Following is the general from of a typical decision making structure found in most of the programming languages −
Swift 4 provides the following types of decision making statements. Click the following links to check their detail.
An if statement consists of a Boolean expression followed by one or more statements.
An if statement can be followed by an optional else statement, which executes when the Boolean expression is false.
An if statement can be followed by an optional else if...else statement, which is very useful to test various conditions using single if...else if statement.
You can use one if or else if statement inside another if or else if statement(s).
A switch statement allows a variable to be tested for equality against a list of values.
We have covered conditional operator ? : in the previous chapter which can be used to replace if...else statements. It has the following general form −
Exp1 ? Exp2 : Exp3;

Where Exp1, Exp2, and Exp3 are expressions. Notice the use and placement of the colon.
The value of a ? expression is determined like this: Exp1 is evaluated. If it is true, then Exp2 is evaluated and becomes the value of the entire ? expression. If Exp1 is false, then Exp3 is evaluated and its value becomes the value of the expression.

    38 Lectures 
     1 hours 

 Ashish Sharma

    13 Lectures 
     2 hours 

 Three Millennials

    7 Lectures 
     1 hours 

 Three Millennials

    22 Lectures 
     1 hours 

 Frahaan Hussain

    12 Lectures 
     39 mins

 Devasena Rajendran

    40 Lectures 
     2.5 hours 

 Grant Klimaytys
 Print
 Add Notes
 Bookmark this page
How to randomly select an item from a tuple in Python?

The choice() function is useful for this purpose. It returns on item randomly selected from any sequence object (tuple in this case)
>>> import random
>>> t1=(11,'aa',12.50,77,'xyz')
>>> item=random.choice(t1)
>>> item
11
>>> item=random.choice(t1)
>>> item
'xyz'
Batch Script - Recursive Functions

The ability to completely encapsulate the body of a function by keeping variable changes local to the function and invisible to the caller. We can now have the ability to call a function recursively making sure each level of recursion works with its own set of variables even though variable names are being reused.
Following example shows how recursive functions can be used.
The example shows how to calculate a Fibonacci number recursively. The recursion stops when the Fibonacci algorism reaches a number greater or equal to a given input number. The example starts with the numbers 0 and 1, the :myFibo function calls itself recursively to calculate the next Fibonacci number until it finds the Fibonacci number greater or equal to 1000000000.
The first argument of the myFibo function is the name of the variable to store the output in. This variable must be initialized to the Fibonacci number to start with and will be used as current Fibonacci number when calling the function and will be set to the subsequent Fibonacci number when the function returns.
@echo off
set "fst = 0"
set "fib = 1"
set "limit = 1000000000"
call:myFibo fib,%fst%,%limit%
echo.The next Fibonacci number greater or equal %limit% is %fib%.
echo.&pause&goto:eof
:myFibo -- calculate recursively
:myFibo -- calculate recursively the next Fibonacci number greater or equal to a limit
SETLOCAL
set /a "Number1 = %~1"
set /a "Number2 = %~2"
set /a "Limit = %~3"
set /a "NumberN = Number1 + Number2"

if /i %NumberN% LSS %Limit% call:myFibo NumberN,%Number1%,%Limit%
(ENDLOCAL
   IF "%~1" NEQ "" SET "%~1 = %NumberN%"
)goto:eof
The above command produces the following output.
The next Fibonacci number greater or equal 1000000000 is 1134903170.

 Print
 Add Notes
 Bookmark this page
JavaScript TypeError - "X" is not a constructor - GeeksforGeeks

24 Jul, 2020
This JavaScript exception is not a constructor that occurs if code tries to use an object or a variable as a constructor, which is not a constructor.
Message:
TypeError: Object doesn't support this action (Edge)
TypeError: "x" is not a constructor

TypeError: Math is not a constructor
TypeError: JSON is not a constructor
TypeError: Symbol is not a constructor
TypeError: Reflect is not a constructor
TypeError: Intl is not a constructor
TypeError: Atomics is not a constructor


Error Type:
TypeError

Cause of Error: Somewhere the code is trying to use an object or a variable as a constructor, which is not a constructor.
Example 1: In this example, the variable(‘var2’) which is a string, is used as a constructor, So the error has occurred.
HTML
<!DOCTYPE html><html><head>    <title>Type Error</title></head><body>    <script>    var var2 = "This is string";    document.write(new var2());    </script></body></html>
Output(In Edge console):
TypeError: Object doesn't support this action

Example 2: In this example, Math is used as a constructor, So the error has occurred.
HTML
<!DOCTYPE html><html><head>    <title>Type Error</title></head><body>    <script>    document.write(new Math());    </script></body></html>
Output(In Edge console):
TypeError: Object doesn't support this action

JavaScript-Errors
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Difference between var, let and const keywords in JavaScript
Difference Between PUT and PATCH Request
How to get character array from string in JavaScript?
Remove elements from a JavaScript Array
How to filter object array based on attributes?
Roadmap to Become a Web Developer in 2022
Installation of Node.js on Linux
How to fetch data from an API in ReactJS ?
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to insert spaces/tabs in text using HTML/CSS?
Formatting dynamic json array JavaScript

Let’s say, we have an array of objects like this −
const arr = [
   {"name1": "firstString"},
   {"name2": "secondString"},
   {"name3": "thirdString"},
   {"name4": "fourthString"},
   {"name5": "fifthString"},
   {"name6": "sixthString"},
];
We are required to write a function that takes one such array of objects and returns an object
with all the properties listed in that object.
So, let’s write the code for this function. It can be done through the Array reduce method −
const arr = [
   {"name1": "firstString"},
   {"name2": "secondString"},
   {"name3": "thirdString"},
   {"name4": "fourthString"},
   {"name5": "fifthString"},
   {"name6": "sixthString"},
];
const reduceArray = arr => {
   return arr.reduce((acc, val) => {
      Object.assign(acc, val);
      return acc;
   }, {});
};
The output in the console will be −
{
   name1: 'firstString',
   name2: 'secondString',
   name3: 'thirdString',
   name4: 'fourthString',
   name5: 'fifthString',
   name6: 'sixthString'
}
Binary Literals and Digit Separators in C# - GeeksforGeeks

30 Apr, 2019
The fixed values are called as Literal. Literal is a value which is used by the variables. Before C# 7.0 six types of literals are available that are an integer, Floating-point, Character, String, Null, Boolean literals. In C# 7.0 there is one more literal is added which is known as Binary Literal. The binary literal is used to store the binary value in a variable. And the binary literal is represented by 0b. Binary literals are mainly used for bitmasks.
Example:
var num = 0b10001
Here when the compiler sees 0b in the variable value, then it automatically treated this num as a binary literal. If you try to run this on the compilers below C# 7.0, then the compiler will throw an error because this feature is introduced in C# 7.0 so, it will only work on C# 7.0 and above compilers.
Example:
// C# program to illustrate the // concept of binary literals.using System;  class GFG {      // Main method    static public void Main()    {          // Creating binary literals         // by prefixing with 0b        var num1 = 0b1001;        var num2 = 0b01000011;          Console.WriteLine("Value of Num1 is: " + num1);        Console.WriteLine("Value of Num2 is: " + num2);        Console.WriteLine("Char value of Num2 is: {0}",                                 Convert.ToChar(num2));    }}
Value of Num1 is: 9
Value of Num2 is: 67
Char value of Num2 is: C

The concept of digit separator is introduced in C# 7.0. With the help of digit separator, you can separate the large number into small parts which makes your code more readable. Underscore(_) is used as a digit separator. When you use digit separator in your code they are simply ignored by the compiler, so the compiler does not print digit separators in the output like as shown in the below example.
Example:
// C# program to illustrate the // concept of digit separators.using System;  class GFG {      // Main method    static public void Main()    {          // Without Using digit separators        long x = 100000022200000202;        long z = 10000000020;          Console.WriteLine("X: {0}", x);        Console.WriteLine("Z: {0}", z);          // Using digit separators        long num1 = 1_00_10_00_00_00;        var num2 = 0b_010_000_000_000_000_000_000_000_000;        long num3 = 1_00_00_00_00_00_00;        var num4 = 0b_1_1000_0000_1000_0000_0011_0000_0000_1000_0001;          Console.WriteLine("Num1: {0}", num1);        Console.WriteLine("Num2: {0}", num2);        Console.WriteLine("Num3: {0}", num3);        Console.WriteLine("Num4: {0}", num4);    }}
X: 100000022200000202
Z: 10000000020
Num1: 1000110000000000
Num2: 33554432
Num3: 1000000000000000000
Num4: 103213629569

CSharp-7.0
C#
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
C# Dictionary with examples
C# | Method Overriding
Destructors in C#
Difference between Ref and Out keywords in C#
C# | Delegates
C# | String.IndexOf( ) Method | Set - 1
Extension Method in C#
Introduction to .NET Framework
C# | Abstract Classes
HashSet in C# with Examples
SQL Query to Exclude Null Values - GeeksforGeeks

23 Sep, 2021
In this article, we will look at how to exclude Null Values from the table using a SQL query.  
A null value indicates no value. It means that the column value is absent in a row. A null value is not the same as a blank space or a zero value. A zero value is an integer and a blank space is a character while a null value is the one that has been left blank.
To exclude the null values from a table we have to create a table with null values. So, let us create a table.
Step 1: Creating table
Syntax:
CREATE TABLE table_name (
   column1 datatype,
   column2 datatype,
   column3 datatype,
  ....);
Query:
CREATE TABLE Student(Name varchar(40),
Department varchar(30),Roll_No int, );
Using the above query student table is created in our database. The student table has three fields Name, Department, and Roll Number of a student. To insert values in the table we have to use the INSERT query.
Output:
Step 2: Insert  Data into the Table
Syntax:
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
Query:
INSERT INTO Student
VALUES ('Rahul Sharma','Electronics',15),
      ('Soha Shaikh','Computer Science',NULL),
      ('Vivek Rao',NULL,31),
      ('Sonali Rane','Electronics',20);
Using the above query we have added the data to our table. We used the NULL keyword to insert NULL values.
Output:
Step 3: View Table Data
We can print the data in the table using the SELECT query as below.
Syntax:
SELECT * FROM table_name
Query:
SELECT * FROM Student
The output will show the table with all the fields because we used ‘*’ in the query. It means that select all fields within the table.
Output:
Step 4: Exclude Null Values
To exclude the null values from the table we need to use IS NOT NULL operator with the WHERE clause.
WHERE Clause:The WHERE clause is used to filter the records.It will extract those records that fulfill the condition.It can be used with SELECT, UPDATE, DELETE queries.
The WHERE clause is used to filter the records.
It will extract those records that fulfill the condition.
It can be used with SELECT, UPDATE, DELETE queries.
IS NOT NULL Operator: This operator is used to test for non-empty values.
This operator is used to test for non-empty values.
Syntax:
SELECT column_names
 FROM table_name
WHERE column_name IS NOT NULL;
Query:
SELECT * FROM Student
WHERE Name IS NOT NULL
AND Department IS NOT NULL
AND Roll_No IS NOT NULL;
To exclude the null values from all the columns we used AND operator. AND operator shows the record if all the conditions are true.
Output:
Picked
SQL-Query
SQL-Server
SQL
SQL
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to Update Multiple Columns in Single Update Statement in SQL?
How to Alter Multiple Columns at Once in SQL Server?
What is Temporary Table in SQL?
SQL Query to Find the Name of a Person Whose Name Starts with Specific Letter
SQL using Python
SQL | Subquery
SQL Query to Convert VARCHAR to INT
SQL | Date functions
SQL - SELECT from Multiple Tables with MS SQL Server
SQL Query to Insert Multiple Rows
PHP Callbacks/Callables

Callback is a pseudo-type in PHP. With PHP 5.4, Callable type hint has been introduced, which is similar to Callback. When some object is identified as callable, it means that it can be used as a function that can be called. A callable can be a built-in or user defined function or a method inside any class.
The is_callable() function can be used to verify if the identifier is a callable or not. PHP has call_user_function() that accepts a function's name as a parameter.
Following example shows a built-in function is a callable.
 Live Demo
<?php
var_dump (is_callable("abs"));
?>
This will produce following result −
bool(true)
In following example a user defined function is tested for being callable.
 Live Demo
<?php
function myfunction(){
   echo "Hello World";
}
echo is_callable("myfunction") . "\n";
call_user_func("myfunction")
?>
This will produce following result −
1
Hello World
To pass a object method as a callable, the object itself and its method are passed as two elements in an array
 Live Demo
<?php
class myclass{
   function mymethod(){
      echo "This is a callable" . "\n";
   }
}
$obj=new myclass();
call_user_func(array($obj, "mymethod"));
//array passed in literal form
call_user_func([$obj, "mymethod"]);
?>
This will produce following result −
This is a callable
This is a callable
Static method in a class can also be passed as callable. Instead of object, name of the class should be first element in array parameter
 Live Demo
<?php
class myclass{
   static function mymethod(){
      echo "This is a callable" . "\n";
   }
}
$obj=new myclass();
call_user_func(array("myclass", "mymethod"));
//using scope resolution operator
call_user_func("myclass::mymethod");
?>
This will produce following result −
This is a callable
This is a callable
BeautifulSoup - Search by text inside a tag - GeeksforGeeks

15 Mar, 2021
Prerequisites: Beautifulsoup
Beautifulsoup is a powerful python module used for web scraping. This article discusses how a specific text can be searched inside a given tag.
Import module
Pass the URL
Request page
Specify the tag to be searched
For Search by text inside tag we need to check condition to with help of string function.
The string function will return the text inside a tag.
When we will navigate tag then we will check the condition with the text.
Return text
We will see search text inside a tag by two method.
This method uses for loop for to search for the text.
Example
Python3
from bs4 import BeautifulSoupimport requests  # sample web pagesample_web_page = 'https://www.geeksforgeeks.org/caching-page-tables/'  # call get method to request that pagepage = requests.get(sample_web_page)  # with the help of beautifulSoup and html parser create soupsoup = BeautifulSoup(page.content, "html.parser")  child_soup = soup.find_all('strong')  text = 'page table base register (PTBR)'  # we will search the tag with in which text is same as given textfor i in child_soup:    if(i.string == text):        print(i)
Output
<strong>page table base register (PTBR)</strong>
It is a one liner alternative of the above example.
Example
Python3
from bs4 import BeautifulSoupimport requests  # sample web pagesample_web_page = 'https://www.geeksforgeeks.org/caching-page-tables/'  # call get method to request that pagepage = requests.get(sample_web_page)  # with the help of beautifulSoup and html parser create soupsoup = BeautifulSoup(page.content, "html.parser")  text = 'CS Theory Course'  # Search by text with the help of lambda functiongfg = soup.find_all(lambda tag: tag.name == "strong" and text in tag.text)  print(gfg)
Output
[<strong>CS Theory Course</strong>]
Picked
Python BeautifulSoup
Python bs4-Exercises
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
How To Convert Python Dictionary To JSON?
How to drop one or multiple columns in Pandas Dataframe
Check if element exists in list in Python
Selecting rows in pandas DataFrame based on conditions
Python | os.path.join() method
Defaultdict in Python
Create a directory in Python
Python | Get unique values from a list
Python | Pandas dataframe.groupby()
Performing distinct on multiple fields in MongoDB?

You can use $group operator along with aggregate framework to perform distinct on multiple fields. Let us first create a collection with documents −
> db.distinctOnMultipleFieldsDemo.insertOne(
...    {
...       "StudentFirstName" : "Chris",
...       "StudentAge" : 21,
...       "StudentCountryName": "US"
...    }
... );
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5cd2e518b64f4b851c3a13d7")
}
> db.distinctOnMultipleFieldsDemo.insertOne(
...    {
...       "StudentFirstName" : "Robert",
...       "StudentAge" : 21,
...       "StudentCountryName": "AUS"
...    }
... );
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5cd2e518b64f4b851c3a13d8")
}
> db.distinctOnMultipleFieldsDemo.insertOne(
...    {
...       "StudentFirstName" : "Chris",
...       "StudentAge" : 22,
...       "StudentCountryName": "UK"
...    }
... );
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5cd2e518b64f4b851c3a13d9")
}
> db.distinctOnMultipleFieldsDemo.insertOne(
...    {
...       "StudentFirstName" : "David",
...       "StudentAge" : 24,
...       "StudentCountryName": "AUS"
...    }
... );
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5cd2e518b64f4b851c3a13da")
}
Following is the query to display all documents from a collection with the help of find() method −
> db.distinctOnMultipleFieldsDemo.find().pretty();
This will produce the following output −
{
   "_id" : ObjectId("5cd2e518b64f4b851c3a13d7"),
   "StudentFirstName" : "Chris",
   "StudentAge" : 21,
   "StudentCountryName" : "US"
}
{
   "_id" : ObjectId("5cd2e518b64f4b851c3a13d8"),
   "StudentFirstName" : "Robert",
   "StudentAge" : 21,
   "StudentCountryName" : "AUS"
}
{
   "_id" : ObjectId("5cd2e518b64f4b851c3a13d9"),
   "StudentFirstName" : "Chris",
   "StudentAge" : 22,
   "StudentCountryName" : "UK"
}
{
   "_id" : ObjectId("5cd2e518b64f4b851c3a13da"),
   "StudentFirstName" : "David",
   "StudentAge" : 24,
   "StudentCountryName" : "AUS"
}
Following is the query to perform distinct on multiple fields in MongoDB −
> db.distinctOnMultipleFieldsDemo.aggregate([
...    {
...       $group:
...       {
...          _id:0,
...          StudentFirstName: {$addToSet: '$StudentFirstName'},
...          StudentAge: {$addToSet: '$StudentAge'},
...          StudentCountryName: {$addToSet: '$StudentCountryName'},
...    }}
... ]);
This will produce the following output −
{ "_id" : 0, "StudentFirstName" : [ "David", "Robert", "Chris" ], "StudentAge" : [ 24, 22, 21 ], "StudentCountryName" : [ "UK", "AUS", "US" ] }
What is use of %n in printf() ?

09 Oct, 2019
In C printf(), %n is a special format specifier which instead of printing something causes printf() to load the variable pointed by the corresponding argument with a value equal to the number of characters that have been printed by printf() before the occurrence of %n.
#include<stdio.h>  int main(){  int c;  printf("geeks for %ngeeks ", &c);  printf("%d", c);  getchar();  return 0;}
The above program prints “geeks for geeks 10”. The first printf() prints “geeks for geeks”. The second printf() prints 10 as there are 10 characters printed (the 10 characters are “geeks for “) before %n in first printf() and c is set to 10 by first printf().
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
C-Input and Output Quiz
C Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
jQuery UI Dialog title Option

12 Jan, 2021
The article explains the title option which is used to set the title in the dialog box. By default, its value is null.
Syntax:
$( ".selector" ).dialog({
    title : "title"
});
Approach: First, add jQuery UI scripts needed for your project.
<link href = “https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css” rel=”stylesheet”><script src = “https://code.jquery.com/jquery-1.10.2.js”></script><script src = “https://code.jquery.com/ui/1.10.4/jquery-ui.js”></script>
Example:
HTML
<!doctype html><html lang="en">  <head>    <meta charset="utf-8">    <link href="https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"        rel="stylesheet">    <script src="https://code.jquery.com/jquery-1.10.2.js"></script>    <script src=        "https://code.jquery.com/ui/1.10.4/jquery-ui.js">    </script>      <script>        $(function () {            $("#gfg").dialog({                autoOpen: false,                title: "GeeksforGeeks"            });            $("#geeks").click(function () {                $("#gfg").dialog("open");            });        });    </script></head>  <body>    <div id="gfg">        Jquery UI| resizable dialog option    </div>          <button id="geeks">Open Dialog</button></body>  </html>
Output:
jQuery-UI
HTML
JQuery
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
JavaScript URIError | Malformed URI Sequence

19 Aug, 2020
This JavaScript exception malformed URI sequence occurs if the encoding or decoding of URI is unsuccessful.
Message:
URIError: The URI to be encoded contains invalid character (Edge)
URIError: malformed URI sequence (Firefox)
URIError: URI malformed (Chrome)

Error Type:
URIError

Cause of the Error: This error is thrown as somewhere in the code, the URI encoding or decoding is unsuccessful.
Example 1: In this example, the value passed is not acceptable, therefore the error has occurred.
HTML
<script>  // Error here  encodeURI('\uD810');</script>
Output:
URIError: URI malformed
Example 2: In this example, the value passed is not acceptable, therefore the error has occurred.
HTML
<script>  // Error here  decodeURIComponent('%E0%B4%A'); </script>
Output:
URIError: URI malformed
JavaScript-Errors
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
pstree Command in Linux with Examples

03 Jun, 2020
Pstree command in Linux that shows the running processes as a tree which is a more convenient way to display the processes hierarchy and makes the output more visually appealing. The root of the tree is either init or the process with the given pid. Pstree can also be installed in other Unix systems.
Syntax:
pstree [options] [pid or username]
1. To display process tree
pstree
It produces process-related information in output.
2. To include command line arguments in output
pstree -a
We do this by using the “-a” command line option. This command now displays command line options for some processes.
3. To display PIDs
pstree -p
To display PIDs for each process name, we use “-p” option.
4. To force pstree to expand identical subtrees in output.
pstree -c
By default, the pstree command merges identical branches by putting them in square brackets and prefixing them with the repetition count. But we can also force the tool to expand identical trees, by using the “-c” command-line option.
5. To sort processes
pstree -n
If we want to sort processes with the same ancestor by PID instead of by name i.e. numeric sort, we use “-n” option.
6. To see who is the owner/user of a process
pstree -u
If we want to find out the owner of a process in parenthesis, use the “-u” option.
7. To highlight the current process or any other process
pstree -h
To highlight the current process and its ancestors use “-h” option. It highlights the specified process (by name/pid)
8. To show process group IDs in output
pstree -g
We can see that process group IDs are shown as decimal numbers in parentheses after each process name.
9. To make pstree display process tree specific to a user.
pstree khushi
It we want to display all process trees rooted at processes owned by a specific user, for this, we have to pass the name of that user as input to the command.
10. To display version information.
pstree -V
When we want to display version information we use “-V” option.
linux-command
Linux-system-commands
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Docker - COPY Instruction
scp command in Linux with Examples
Introduction to Linux Operating System
chown command in Linux with Examples
chmod command in Linux with examples
SED command in Linux | Set 2
nohup Command in Linux with Examples
Array Basics in Shell Scripting | Set 1
How to Permanently Disable Swap in Linux?
mv command in Linux with examples
ROUND() Function in SQL Server

30 Dec, 2020
ROUND() function :This function in SQL Server is used to round off a specified number to a specified decimal places.
Features :
This function is used to round off a specified number to a specified decimal places.
This function accepts only all type of numbers i.e., positive, negative, zero.
This function accepts fraction numbers.
This function always returns the number after rounded to the specified decimal places.
Syntax :
ROUND(number, decimals, operation)
Parameter :This method accepts three parameters as given below :
number : Specified number to be rounded off.
decimals : Specified number of decimal places up to which the given number is to be rounded.
operation : This is optional parameter. If it’s value is 0, it rounds the result to the number of decimal. If another value than 0, it truncates the result to the number of decimals. Default value is 0
Returns :It returns the number after rounded to the specified places.
Example-1 :Getting a rounded number up to next two decimal places.
SELECT ROUND(12.3456, 2);
Output :
12.3500
Example-2 :Getting the number to the next two decimal places with the operational parameter 1 which says only to truncate the specified number (-23.456) to the given decimal places i, e., 2.
SELECT ROUND(12.3456, 2, 1);
Output :
12.3400
Example-3 :Using ROUND() function with a variable and getting the rounded number to -2 decimal place.
DECLARE @Parameter_Value FLOAT;
SET @Parameter_Value = -2;
SELECT ROUND(123.4567, @Parameter_Value);

Output :
100.0000
Example-4 :
Getting the rounded number to the zero number of decimal places.
SELECT ROUND(123.467, 0);
Output :
123.000
Example-5 :Using ROUND() function with variables and getting the rounded number to the 2 decimal places.
DECLARE @Number_Value FLOAT;
DECLARE @Decimals_Value INT;
SET @Number_Value = -23.456;
SET @Decimals_Value = 2;
SELECT ROUND(@Number_Value, @Decimals_Value);

Output :
-23.460000000000001
Example-6 :Getting the number to the next two decimal places with the operational parameter 1 which says only to truncate the specified number (-23.456) to the given decimal places i.e., 2.
SELECT ROUND(-23.456, 2, 1);
Output :
-23.450
Application :This function is used to return the number after rounded to the specified places.
DBMS-SQL
SQL-Server
SQL
SQL
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
QTP - Descriptive Programming

QTP scripts can execute only if the objects are present in the Object Repository. The descriptions of the Objects are created using Descriptive programming −
When the testers want to perform an operation on an object that is not present in the object repository
When the testers want to perform an operation on an object that is not present in the object repository
When objects in the application are very dynamic in nature.
When objects in the application are very dynamic in nature.
When the Object Repository grows big, it results in poor Performance as the size of the Object Repository increases.
When the Object Repository grows big, it results in poor Performance as the size of the Object Repository increases.
When the framework is built, such that it has been decided not to use Object Repository at all.
When the framework is built, such that it has been decided not to use Object Repository at all.
When testers want to perform an action on the application at run-time without having the knowledge of object's unique properties.
When testers want to perform an action on the application at run-time without having the knowledge of object's unique properties.
There are two ways to scripting using Descriptive Programming technique. They are −
Description Objects
Description Strings
Script is developed using Description Objects that depend upon the properties used and their corresponding values. Then, these descriptions are used to build the script.
'Creating a description object
Set btncalc = Description.Create()

'Add descriptions and properties
btncalc("type").value = "Button"
btncalc("name").value = "calculate"
btncalc("html tag").value = "INPUT"

' Use the same to script it
Browser("Math Calc").Page("Num Calculator").WebButton(btncalc).Click
The description of the objects is developed using the properties and values as strings as shown below.
Browser("Math Calc").Page("Num Calculator").WebButton("html 
tag:=INPUT","type:=Button","name:=calculate").Click

QTP provides the ChildObjects method, which enables us to create a collection of objects. The parent objects precedes ChildObjects.
Dim oDesc
Set oDesc = Description.Create
oDesc("micclass").value = "Link"

'Find all the Links
Set obj = Browser("Math Calc").Page("Math Calc").ChildObjects(oDesc)

Dim i
'obj.Count value has the number of links in the page

For i = 0 to obj.Count - 1	 
   'get the name of all the links in the page			
   x = obj(i).GetROProperty("innerhtml") 
   print x 
Next
Descriptive programming is used to write the script based on ordinal identifiers, which will enable QTP to act on those objects when two or more objects have the same properties.
' Using Location
Dim Obj
Set Obj = Browser("title:=.*google.*").Page("micclass:=Page")
Obj.WebEdit("name:=Test","location:=0").Set "ABC"
Obj.WebEdit("name:=Test","location:=1").Set "123"
 
' Index
Obj.WebEdit("name:=Test","index:=0").Set "1123"
Obj.WebEdit("name:=Test","index:=1").Set "2222"
 
' Creation Time
Browser("creationtime:=0").Sync
Browser("creationtime:=1").Sync
Browser("creationtime:=2").Sync

    108 Lectures 
     8 hours 

 Pavan Lalwani
 Print
 Add Notes
 Bookmark this page
C# program to get the last element from an array

Firstly, set an array −
string[] str = new string[]{
   "Java",
   "HTML",
   "jQuery",
   "JavaScript",
   "Bootstrap"
};
To get the value of the last element, get the length and display the following value −
str[str.Length - 1]
The above returns the last element.
Here is the complete code −
 Live Demo
using System;

public class Demo {
   public static void Main() {
      string[] str = new string[] {
         "Java",
         "HTML",
         "jQuery",
         "JavaScript",
         "Bootstrap"
      };
      Console.WriteLine("Array...");
      foreach(string res in str) {
         Console.WriteLine(res);
      }
      Console.WriteLine("Last element: "+str[str.Length - 1]);
   }
}
Array...
Java
HTML
jQuery
JavaScript
Bootstrap
Last element: Bootstrap
Arduino - Compound Operators

Assume variable A holds 10 and variable B holds 20 then −
void loop () {
   int a = 10,b = 20
   int c = 0;
   
   a++;
   a--;
   b += a;
   b -= a;
   b *= a;
   b /= a;
   a %= b;
   a |= b;
   a &= b;
}
a = 11
a = 9
b = 30
b = 10
b = 200
b = 2
a = 0
a = 0
a = 30


    65 Lectures 
     6.5 hours 

 Amit Rana

    43 Lectures 
     3 hours 

 Amit Rana

    20 Lectures 
     2 hours 

 Ashraf Said

    19 Lectures 
     1.5 hours 

 Ashraf Said

    11 Lectures 
     47 mins

 Ashraf Said

    9 Lectures 
     41 mins

 Ashraf Said
 Print
 Add Notes
 Bookmark this page
How to rethrow InnerException without losing stack trace in C#?

In c#, the throw is a keyword and it is useful to throw an exception manually during the execution of the program and we can handle those thrown exceptions using try−catch blocks based on our requirements.
By using throw keyword in the catch block, we can re-throw an exception that is handled in the catch block. The re-throwing an exception is useful when we want to pass an exception to the caller to handle it in a way they want.
Following is the example of re−throwing an exception to the caller using throw keyword with try-catch blocks in c#.
class Program{
   static void Main(string[] args){
      try{
         Method2();
      }
      catch (System.Exception ex){
         System.Console.WriteLine($"{ex.StackTrace.ToString()} {ex.Message}");
      }
      Console.ReadLine();
   }
   static void Method2(){
      try{
         Method1();
      }
      catch (System.Exception){
         throw;
      }
   }
   static void Method1(){
      try{
         throw new NullReferenceException("Null Exception error");
      }
      catch (System.Exception){
         throw;
      }
   }
}
This is how we can re-throw an exception to the caller using throw keyword in catch block based on our requirements.
at DemoApplication.Program.Method1() in C:\Users\Koushik\Desktop\Questions\ConsoleApp\Program.cs:line 49
at DemoApplication.Program.Method2() in C:\Users\Koushik\Desktop\Questions\ConsoleApp\Program.cs:line 37
at DemoApplication.Program.Main(String[] args) in C:\Users\Koushik\Desktop\Questions\ConsoleApp\Program.cs:line 24 Null Exception error
Dart Programming - Enumeration

An enumeration is used for defining named constant values. An enumerated type is declared using the enum keyword.
enum enum_name {  
   enumeration list 
}

Where,
The enum_name specifies the enumeration type name
The enumeration list is a comma-separated list of identifiers
Each of the symbols in the enumeration list stands for an integer value, one greater than the symbol that precedes it. By default, the value of the first enumeration symbol is 0.
enum Status { 
   none, 
   running, 
   stopped, 
   paused 
}
enum Status { 
   none, 
   running, 
   stopped, 
   paused 
}  
void main() { 
   print(Status.values); 
   Status.values.forEach((v) => print('value: $v, index: ${v.index}'));
   print('running: ${Status.running}, ${Status.running.index}'); 
   print('running index: ${Status.values[1]}'); 
}
It will produce the following output −
[Status.none, Status.running, Status.stopped, Status.paused] 
value: Status.none, index: 0 
value: Status.running, index: 1 
value: Status.stopped, index: 2 
value: Status.paused, index: 3 
running: Status.running, 1 
running index: Status.running 


    44 Lectures 
     4.5 hours 

 Sriyank Siddhartha

    34 Lectures 
     4 hours 

 Sriyank Siddhartha

    69 Lectures 
     4 hours 

 Frahaan Hussain

    117 Lectures 
     10 hours 

 Frahaan Hussain

    22 Lectures 
     1.5 hours 

 Pranjal Srivastava

    34 Lectures 
     3 hours 

 Pranjal Srivastava
 Print
 Add Notes
 Bookmark this page
C# program to concat two or more Lists

Set three lists −
// three lists
var list1 = new List<int>{3, 4};
var list2 = new List<int>{1, 2, 3};
var list3 = new List<int>{2, 5, 6};
Now, use the Concat mthod to concat the above lists −
var res1 = list1.Concat(list2);
var res2 = res1.Concat(list3);
Here is the complete code −
 Live Demo
using System.Collections.Generic;
using System.Linq;
using System;

public class Demo {
   public static void Main() {

      // three lists
      var list1 = new List<int>{3, 4};
      var list2 = new List<int>{1, 2, 3};
      var list3 = new List<int>{2, 5, 6};

      // concat
      var res1 = list1.Concat(list2);
      var res2 = res1.Concat(list3);

      foreach(int i in res2) {
         Console.WriteLine(i);
      }
   }
}
3
4
1
2
3
2
5
6
C++ Program to Display Armstrong Number Between Two Intervals

An Armstrong Number is a number where the sum of the digits raised to the power of total number of digits is equal to the number.
Some examples of Armstrong numbers are as follows −
3 = 3^1
153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153
407 = 4^3 + 0^3 + 7^3 = 64 +0 + 343 = 407
1634 = 1^4 + 6^4 + 3^4 + 4^4 = 1 + 1296 + 81 + 256 = 1634
A program that displays the Armstrong numbers between two intervals is as follows.
 Live Demo
#include <iostream>
#include <cmath>
using namespace std;
int main() {
   int lowerbound, upperbound, digitSum, temp, remainderNum, digitNum ;
   lowerbound = 100;
   upperbound = 500;
   cout<<"Armstrong Numbers between "<<lowerbound<<" and "<<upperbound<<" are: ";
   for(int num = lowerbound; num <= upperbound; num++) {
      temp = num;
      digitNum = 0;
      while (temp != 0) {
         digitNum++;
         temp = temp/10;
      }
      temp = num;
      digitSum = 0;
      while (temp != 0) {
         remainderNum = temp%10;
         digitSum = digitSum + pow(remainderNum, digitNum);
         temp = temp/10;
      }
      if (num == digitSum)
      cout<<num<<" ";
   }
   return 0;
}
Armstrong Numbers between 100 and 500 are: 153 370 371 407
In the above program, Armstrong numbers between the given intervals are found. This is done using multiple steps. The lowerbound and upperbound of the interval are given. Using these, a for loop is started from lowerbound to upperbound and each number is evaluated to see if it is an Armstrong number or not.
This can be seen in the following code snippet.
lowerbound = 100;
upperbound = 500;
cout<<"Armstrong Numbers between "<<lowerbound<<" and "<<upperbound<<" are: ";
for(int num = lowerbound; num <= upperbound; num++)
In the for loop, first the number of digits in the number i.e in num are found. This is done by adding one to digitNum for each digit.
This is demonstrated by the following code snippet.
temp = num;
digitNum = 0;
while (temp != 0) {
   digitNum++;
   temp = temp/10;
}
After the number of digits are known, digitSum is calculated by adding each digit raised to the power of digitNum i.e. number of digits.
This can be seen in the following code snippet.
temp = num;
digitSum = 0;
while (temp != 0) {
   remainderNum = temp%10;
   digitSum = digitSum + pow(remainderNum, digitNum);
   temp = temp/10;
}
If the number is equal to the digitSum, then that number is an Armstrong number and it is printed. If not, then it is not an Armstrong number. This is seen in the below code snippet.
if (num == digitSum)
cout<<num<<" ";
Find minimum element of ArrayList with Java Collections

In order to compute minimum element of ArrayList with Java Collections, we use the Collections.min() method. The java.util.Collections.min() returns the minimum element of the given collection. All elements must be mutually comparable and implement the comparable interface. They shouldn’t throw a ClassCastException.
Declaration −The Collections.min() method is declared as follows −
public static <T extends Object & Comparable> T min(Collection c)
where c is the collection object whose minimum is to be found.
Let us see a program to find the minimum element of ArrayList with Java collections −
 Live Demo
import java.util.*;
public class Example {
   public static void main (String[] args) {
      List<Integer> list = new ArrayList<Integer>();
      try {
         list.add(14);
         list.add(2);
         list.add(73);
         System.out.println("Minimum element : " + Collections.min(list));
      }
      catch (ClassCastException | NoSuchElementException e) {
         System.out.println("Exception caught : " + e);
      }
   }
}
Minimum element : 2
Microprocessor - 8085 Instruction Sets

Let us take a look at the programming of 8085 Microprocessor.
Instruction sets are instruction codes to perform some task. It is classified into five categories.
Following is the table showing the list of Control instructions with their meanings.
Following is the table showing the list of Logical instructions with their meanings.
Following is the table showing the list of Branching instructions with their meanings.
Following is the table showing the list of Arithmetic instructions with their meanings.
Following is the table showing the list of Data-transfer instructions with their meanings.
Now, let us take a look at some program demonstrations using the above instructions −
Write a program to add data at 3005H & 3006H memory location and store the result at 3007H memory location.
Problem demo −
(3005H) = 14H 
   (3006H) = 89H

Result −
14H + 89H = 9DH
The program code can be written like this −
LXI H 3005H   : "HL points 3005H" 
MOV A, M      : "Getting first operand" 
INX H         : "HL points 3006H" 
ADD M         : "Add second operand" 
INX H         : "HL points 3007H" 
MOV M, A      : "Store result at 3007H" 
HLT           : "Exit program" 
Write a program to exchange the data at 5000M& 6000M memory location.
LDA 5000M   : "Getting the contents at5000M location into accumulator" 
MOV B, A    : "Save the contents into B register" 
LDA 6000M   : "Getting the contents at 6000M location into accumulator" 
STA 5000M   : "Store the contents of accumulator at address 5000M" 
MOV A, B    : "Get the saved contents back into A register" 
STA 6000M   : "Store the contents of accumulator at address 6000M" 
Write a program to arrange first 10 numbers from memory address 3000H in an ascending order.
MVI B, 09         :"Initialize counter"      
START             :"LXI H, 3000H: Initialize memory pointer" 
MVI C, 09H        :"Initialize counter 2" 
BACK: MOV A, M    :"Get the number" 
INX H             :"Increment memory pointer" 
CMP M             :"Compare number with next number" 
JC SKIP           :"If less, don’t interchange" 
JZ SKIP           :"If equal, don’t interchange" 
MOV D, M 
MOV M, A 
DCX H 
MOV M, D 
INX H             :"Interchange two numbers" 
SKIP:DCR C        :"Decrement counter 2" 
JNZ BACK          :"If not zero, repeat" 
DCR B             :"Decrement counter 1" 
JNZ START 
HLT               :"Terminate program execution" 

    50 Lectures 
     6.5 hours 

 Gowthami Swarna
 Print
 Add Notes
 Bookmark this page
C++ Program to Find the Edge Connectivity of a Graph

In this program we need to find the Edge Connectivity of a Graph. An Edge Connectivity of a Graph of a graph means it is a bridge, removing it graph will be disconnected. Number of connected components increases with the removing of bridge in a disconnected undirected graph.
Begin
   Function connections() is a recursive function to find out the connections:
   A) Mark the current node un visited.
   B) Initialize time and low value
   C) Go through all vertices adjacent to this
   D) Check if the subtree rooted with x has a connection to one of the ancestors of w. If the lowest vertex reachable from subtree under x is below u in DFS tree, then w-x has a connection.
   E) Update low value of w for parent function calls.
End
Begin
   Function Con() that uses connections():
   A) Mark all the vertices as unvisited.
   B) Initialize par and visited, and connections.
   C) Print the connections between the edges in the graph.
End
#include<iostream>
#include <list>
#define N -1
using namespace std;
class G {
   //declaration of functions
   int n;
   list<int> *adj;
   void connections(int n, bool visited[], int disc[], int low[],
   int par[]);
   public:
      G(int n); //constructor
      void addEd(int w, int x);
      void Con();
};
G::G(int n) {
   this->n = n;
   adj = new list<int> [n];
}
//add edges to the graph
void G::addEd(int w, int x) {
   adj[x].push_back(w); //add u to v's list
   adj[w].push_back(x); //add v to u's list
}
void G::connections(int w, bool visited[], int dis[], int low[], int par[]) {
   static int t = 0;
   //mark current node as visited
   visited[w] = true;
   dis[w] = low[w] = ++t;
   //Go through all adjacent vertices
   list<int>::iterator i;
   for (i = adj[w].begin(); i != adj[w].end(); ++i) {
      int x = *i; //x is current adjacent
      if (!visited[x]) {
         par[x] = w;
         connections(x, visited, dis, low, par);
         low[w] = min(low[w], low[x]);
         // If the lowest vertex reachable from subtree under x is below w in DFS tree, then w-x is a connection
         if (low[x] > dis[w])
            cout << w << " " << x << endl;
      } else if (x != par[w])
         low[w] = min(low[w], dis[x]);
   }
}
void G::Con() {
   // Mark all the vertices as unvisited
   bool *visited = new bool[n];
   int *dis = new int[n];
   int *low = new int[n];
   int *par = new int[n];
   for (int i = 0; i < n; i++) {
      par[i] = N;
      visited[i] = false;
   }
   //call the function connections() to find edge connections
   for (int i = 0; i < n; i++)
      if (visited[i] == false)
         connections(i, visited, dis, low, par);
}
int main() {
   cout << "\nConnections in first graph \n";
   G g1(5);
   g1.addEd(1, 2);
   g1.addEd(3, 2);
   g1.addEd(2, 1);
   g1.addEd(0, 1);
   g1.addEd(1, 4);
   g1.Con();
   return 0;
}
Connections in first graph
2 3
1 2
1 4
0 1
Python | Pandas DatetimeIndex.floor() - GeeksforGeeks

29 Dec, 2018
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
Pandas DatetimeIndex.floor() function floor the data to the specified frequency. The function takes the target frequency as input. It returns a new DatetimeIndex object.
Syntax: DatetimeIndex.floor(freq)
Parameters :freq : The frequency level to floor the index to. Must be a fixed frequency like ‘S’ (second) not ‘ME’ (month end).
Return : Index of the same type for a DatetimeIndex or TimedeltaIndex, or a Series with the same index for a Series.
Example #1: Use DatetimeIndex.floor() function to floor the data of the DatetimeIndex object to the specified frequency.
# importing pandas as pdimport pandas as pd  # Create the DatetimeIndex# Here 'S' represents secondly frequency didx = pd.DatetimeIndex(start ='2000-01-15 08:00', freq ='S', periods = 4)  # Print the DatetimeIndexprint(didx)
Output :
Now we want to floor the second based frequency of the DatetimeIndex object to minute based frequency
# convert to the passed frequency# 'T' represents minute based frequencydidx.floor('T')
Output :
As we can see in the output, the function has floored the values of the DatetimeIndex object to the desired frequency. Example #2: Use DatetimeIndex.floor() function to floor the data of the DatetimeIndex object to the specified frequency.
# importing pandas as pdimport pandas as pd  # Create the DatetimeIndex# Here 'T' represents minutely frequency didx = pd.DatetimeIndex(start ='2000-01-15 08:00', freq ='T', periods = 4)  # Print the DatetimeIndexprint(didx)
Output :
Now we want to floor the minute based frequency of the DatetimeIndex object to hour based frequency
# floor minute based frequency to hour based frequencydidx.floor('H')
Output :As we can see in the output, the function has floored the values of the DatetimeIndex object to the desired frequency.
Python pandas-datetimeIndex
Python-pandas
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
How To Convert Python Dictionary To JSON?
Check if element exists in list in Python
How to drop one or multiple columns in Pandas Dataframe
Python Classes and Objects
Python | os.path.join() method
Create a directory in Python
Defaultdict in Python
Python | Pandas dataframe.groupby()
Python | Get unique values from a list