messages listlengths 2 2 | instruction stringlengths 14 288 | input stringlengths 0 635 | output stringlengths 1 3.91k |
|---|---|---|---|
[
{
"role": "user",
"content": "Write a function in Python to remove a given element from a list.\n\nlist = ['A', 'B', 'C', 'D']\nelement = 'B'"
},
{
"role": "assistant",
"content": "def remove_element(list, element): \n if element in list: \n list.remove(element)\n return list\n\nprint(remov... | Write a function in Python to remove a given element from a list. | list = ['A', 'B', 'C', 'D']
element = 'B' | def remove_element(list, element):
if element in list:
list.remove(element)
return list
print(remove_element(list, element)) |
[
{
"role": "user",
"content": "Construct a while loop statement to print only even numbers between 0 to 10 in Python."
},
{
"role": "assistant",
"content": "i = 0\n\nwhile i <= 10: \n if i % 2 == 0:\n print(i)\n i = i + 1"
}
] | Construct a while loop statement to print only even numbers between 0 to 10 in Python. | i = 0
while i <= 10:
if i % 2 == 0:
print(i)
i = i + 1 | |
[
{
"role": "user",
"content": "Develop a Python class for handling the API calls."
},
{
"role": "assistant",
"content": "class APIHandler:\n def __init__(self, base_url, api_key):\n self.base_url = base_url\n self.api_key = api_key\n \n def get(self, endpoint):\n res... | Develop a Python class for handling the API calls. | class APIHandler:
def __init__(self, base_url, api_key):
self.base_url = base_url
self.api_key = api_key
def get(self, endpoint):
response = requests.get(self.base_url + endpoint)
return response
def post(self, endpoint, data):
headers = {'Authorization': 'B... | |
[
{
"role": "user",
"content": "What programming language is used to create a web page?"
},
{
"role": "assistant",
"content": "HTML is the most commonly used language for creating web pages. CSS and JavaScript can also be used."
}
] | What programming language is used to create a web page? | HTML is the most commonly used language for creating web pages. CSS and JavaScript can also be used. | |
[
{
"role": "user",
"content": "Write a C program to print the numbers from 1 to 100, with the following conditions:\n\nif the number is divisible by 2, print \"fizz\"\nif the number is divisible by 3, print \"buzz\"\nif the number is divisible by both 2 and 3, print \"fizzbuzz\""
},
{
"role": "assist... | Write a C program to print the numbers from 1 to 100, with the following conditions:
if the number is divisible by 2, print "fizz"
if the number is divisible by 3, print "buzz"
if the number is divisible by both 2 and 3, print "fizzbuzz" | #include <stdio.h>
int main(void)
{
int i;
for (i=1; i<=100; i++)
{
// number divisible by 3 and 5 both
if (i % 3 == 0 && i % 5 == 0)
printf("fizzbuzz\n");
// number divisible by 3 only
else if (i % 3 == 0)
printf("fizz\n");
... | |
[
{
"role": "user",
"content": "Create a C program to remove a specified character from a given string.\n\nString = \"Hello World!\", Character = 'o'"
},
{
"role": "assistant",
"content": "#include <stdio.h>\n#include <string.h>\n\nint main() \n{\n /* Input String */\n char str[] = \"Hello W... | Create a C program to remove a specified character from a given string. | String = "Hello World!", Character = 'o' | #include <stdio.h>
#include <string.h>
int main()
{
/* Input String */
char str[] = "Hello World!";
int index;
/* Specified Character */
char ch = 'o';
index = 0;
/* Remove the character from the string */
while (str[index] != '\0') {
/* If the character matches with... |
[
{
"role": "user",
"content": "We need to find the maximum element in a given array of numbers.\n\n[1, 2, 3, 4, 5]"
},
{
"role": "assistant",
"content": "def find_max(arr):\n maximum = arr[0]\n for i in arr[1:]:\n if i > maximum:\n maximum = i\n return maximum"
}
] | We need to find the maximum element in a given array of numbers. | [1, 2, 3, 4, 5] | def find_max(arr):
maximum = arr[0]
for i in arr[1:]:
if i > maximum:
maximum = i
return maximum |
[
{
"role": "user",
"content": "Fill the missing values below to make the function work properly.\n\ndef compound_calculation(x, y, z=?):\n '''This function calculates the compound amount at the given rate.'''\n return (x + y) * z"
},
{
"role": "assistant",
"content": "def compound_calculati... | Fill the missing values below to make the function work properly. | def compound_calculation(x, y, z=?):
'''This function calculates the compound amount at the given rate.'''
return (x + y) * z | def compound_calculation(x, y, z=1.1):
'''This function calculates the compound amount at the given rate.'''
return (x + y) * z |
[
{
"role": "user",
"content": "Determine the sum of the first n elements in a given array.\n\nAn array containing [2, 4, 6, 8, 10]"
},
{
"role": "assistant",
"content": "The sum of the first 5 elements in the given array is 30."
}
] | Determine the sum of the first n elements in a given array. | An array containing [2, 4, 6, 8, 10] | The sum of the first 5 elements in the given array is 30. |
[
{
"role": "user",
"content": "Replace all characters in the given string with the given character\n\nstring = \"Hello World\"\nchar = \"x\""
},
{
"role": "assistant",
"content": "def replace_chars(string, char):\n output = \"\"\n for c in string:\n output += char\n return output\... | Replace all characters in the given string with the given character | string = "Hello World"
char = "x" | def replace_chars(string, char):
output = ""
for c in string:
output += char
return output
replace_chars(string, char) # Output: xxxxx xxxxx |
[
{
"role": "user",
"content": "Generate a function in Python that takes a number and a list as input and finds the number of occurrences of the number in the list."
},
{
"role": "assistant",
"content": "def count_occurrence(number, input_list):\n return input_list.count(number)"
}
] | Generate a function in Python that takes a number and a list as input and finds the number of occurrences of the number in the list. | def count_occurrence(number, input_list):
return input_list.count(number) | |
[
{
"role": "user",
"content": "Write a function to parse a string and return a dictionary where each character in the string is mapped to its frequency.\n\n\"hello world\""
},
{
"role": "assistant",
"content": "def get_frequency_map(string): \n frequency_map = {}\n # count the frequency of ... | Write a function to parse a string and return a dictionary where each character in the string is mapped to its frequency. | "hello world" | def get_frequency_map(string):
frequency_map = {}
# count the frequency of each character
for char in string:
if char in frequency_map:
frequency_map[char] += 1
else:
frequency_map[char] = 1
return frequency_map
string = "hello world"
frequency_map = get_frequ... |
[
{
"role": "user",
"content": "Determine the maximum sum of a subarray within the given array.\n\n[-2, 1, -3, 4, -1, 2, 1, -5, 4]."
},
{
"role": "assistant",
"content": "let max_sum = 0;\nlet current_sum = 0;\n\nfor (let i=0; i < arr.length; i++)\n{\n current_sum += arr[i];\n \n if (curr... | Determine the maximum sum of a subarray within the given array. | [-2, 1, -3, 4, -1, 2, 1, -5, 4]. | let max_sum = 0;
let current_sum = 0;
for (let i=0; i < arr.length; i++)
{
current_sum += arr[i];
if (current_sum < 0)
current_sum = 0;
max_sum = Math.max(current_sum, max_sum);
}
console.log(max_sum); |
[
{
"role": "user",
"content": "Create a bash script to print the name of the directory the script was started from."
},
{
"role": "assistant",
"content": "#!/bin/bash\necho $(pwd)"
}
] | Create a bash script to print the name of the directory the script was started from. | #!/bin/bash
echo $(pwd) | |
[
{
"role": "user",
"content": "Design a program to reverse a string without using the built-in 'reverse' method.\n\nstring = \"Hello World\""
},
{
"role": "assistant",
"content": "def reverseStr(str):\n revStr = \"\" \n i = len(str) - 1\n while i >= 0: \n revStr += str[i] \n ... | Design a program to reverse a string without using the built-in 'reverse' method. | string = "Hello World" | def reverseStr(str):
revStr = ""
i = len(str) - 1
while i >= 0:
revStr += str[i]
i = i - 1
return revStr |
[
{
"role": "user",
"content": "You should edit this code and make it into a working code that prints \"Hello, world!\"\n\ncout << \"Hello, World!\""
},
{
"role": "assistant",
"content": "#include <iostream>\n\nint main() {\n std::cout << \"Hello, World!\" << std::endl;\n return 0;\n}"
}
] | You should edit this code and make it into a working code that prints "Hello, world!" | cout << "Hello, World!" | #include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
} |
[
{
"role": "user",
"content": "Create a Ruby class that has two methods - one for calculating the result of multiplications and one for calculating the addition of two numbers."
},
{
"role": "assistant",
"content": "class Calculator\n def multiply(a, b)\n return a * b\n end\n\n de... | Create a Ruby class that has two methods - one for calculating the result of multiplications and one for calculating the addition of two numbers. | class Calculator
def multiply(a, b)
return a * b
end
def add(a, b)
return a + b
end
end | |
[
{
"role": "user",
"content": "Write a function to normalize a vector in C++."
},
{
"role": "assistant",
"content": "#include <iostream>\n#include <algorithm>\n#include <cmath>\n \n// Function to normalize a vector\nvoid normalize(std::vector<float>& vector)\n{\n // Compute the magnitude\n ... | Write a function to normalize a vector in C++. | #include <iostream>
#include <algorithm>
#include <cmath>
// Function to normalize a vector
void normalize(std::vector<float>& vector)
{
// Compute the magnitude
float magnitude = 0.0;
for (int i = 0; i < vector.size(); i++)
magnitude += vector[i] * vector[i];
magnitude = sqrt(magnitude);
... | |
[
{
"role": "user",
"content": "Compare two strings and remove all letters from the first string which are present in the second string and vice versa.\n\nstring1 = \"Hello World!\"\nstring2 = \"Bye World!\""
},
{
"role": "assistant",
"content": "def compare_and_remove_letters(string1, string2):\n... | Compare two strings and remove all letters from the first string which are present in the second string and vice versa. | string1 = "Hello World!"
string2 = "Bye World!" | def compare_and_remove_letters(string1, string2):
result = ""
for i in string1:
if i not in string2:
result += i
for i in string2:
if i not in string1:
result += i
return result
# example
print(compare_and_remove_letters("Hello World!", "Bye World!")) # output: B... |
[
{
"role": "user",
"content": "Create a loop to iterate through the elements of an array arr."
},
{
"role": "assistant",
"content": "for (int i = 0; i < arr.length; i++) { \n // code to run for each element\n}"
}
] | Create a loop to iterate through the elements of an array arr. | for (int i = 0; i < arr.length; i++) {
// code to run for each element
} | |
[
{
"role": "user",
"content": "Create a valid regular expression that matches a valid U.S. phone number?"
},
{
"role": "assistant",
"content": "^\\d{10}$|(^\\d{3}\\-\\d{3}\\-\\d{4}$)|(^\\(\\d{3}\\) \\d{3}\\-\\d{4}$)"
}
] | Create a valid regular expression that matches a valid U.S. phone number? | ^\d{10}$|(^\d{3}\-\d{3}\-\d{4}$)|(^\(\d{3}\) \d{3}\-\d{4}$) | |
[
{
"role": "user",
"content": "Create a class for a basketball team."
},
{
"role": "assistant",
"content": "class BasketballTeam:\n\n def __init__(self, name, players):\n self.name = name\n self.players = players\n \n def get_name(self):\n return self.name\n \n ... | Create a class for a basketball team. | class BasketballTeam:
def __init__(self, name, players):
self.name = name
self.players = players
def get_name(self):
return self.name
def get_players(self):
return self.players
def add_player(self, player):
self.players.append(player)
retur... | |
[
{
"role": "user",
"content": "Generate a query to return copies of the records in a table.\n\nTable Name: Products"
},
{
"role": "assistant",
"content": "SELECT Products.*\nFROM Products;"
}
] | Generate a query to return copies of the records in a table. | Table Name: Products | SELECT Products.*
FROM Products; |
[
{
"role": "user",
"content": "Write a HTML code to display a ordered list of five items inside a div with the classname \"list\"."
},
{
"role": "assistant",
"content": "<div class=\"list\">\n <ol>\n <li>Item 1</li>\n <li>Item 2</li>\n <li>Item 3</li>\n <li>Item 4</li>\n <li>Item ... | Write a HTML code to display a ordered list of five items inside a div with the classname "list". | <div class="list">
<ol>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ol>
</div> | |
[
{
"role": "user",
"content": "Perform checksum calculation on the following string \"HelloWorld\"."
},
{
"role": "assistant",
"content": "// Function to calculate the checksum of a given string \n// *str is the given string \nlong calculateChecksum(string str) \n{ \n\tlong checksum = 0; \n \n\t... | Perform checksum calculation on the following string "HelloWorld". | // Function to calculate the checksum of a given string
// *str is the given string
long calculateChecksum(string str)
{
long checksum = 0;
for (int i = 0; i < str.length(); i++) {
checksum += str.at(i);
}
return checksum;
}
// Output: checksum = 483 (for "HelloWorld") | |
[
{
"role": "user",
"content": "Write a function in C that returns the maximum element in an integer array."
},
{
"role": "assistant",
"content": "int findMaximum(int arr[], int size)\n{\n int max = arr[0];\n for (int i=1; i<size; i++)\n if (arr[i] > max)\n max = arr[i];\n \... | Write a function in C that returns the maximum element in an integer array. | int findMaximum(int arr[], int size)
{
int max = arr[0];
for (int i=1; i<size; i++)
if (arr[i] > max)
max = arr[i];
return max;
} | |
[
{
"role": "user",
"content": "Extract the first 3 characters of an input string using Python.\n\nString = \"Hello World!\""
},
{
"role": "assistant",
"content": "string = \"Hello World!\"\n\n#Extract first 3 characters \nfirst_3_characters = string[0:3]\n\nprint(first_3_characters)"
}
] | Extract the first 3 characters of an input string using Python. | String = "Hello World!" | string = "Hello World!"
#Extract first 3 characters
first_3_characters = string[0:3]
print(first_3_characters) |
[
{
"role": "user",
"content": "Create a class in Java to store student details\n\nAttributes: id (int), name (String), grade (int)"
},
{
"role": "assistant",
"content": "public class Student{\n // Attributes \n private int id;\n private String name;\n private int grade;\n \n // ... | Create a class in Java to store student details | Attributes: id (int), name (String), grade (int) | public class Student{
// Attributes
private int id;
private String name;
private int grade;
// Constructor
public Student(int id, String name, int grade){
this.id = id;
this.name = name;
this.grade = grade;
}
// Getters and setters
public int getI... |
[
{
"role": "user",
"content": "Create a function 'convertStringToInt' that takes a string and converts it into an integer."
},
{
"role": "assistant",
"content": "def convertStringToInt(string): \n convertValue = int(string) \n return convertValue"
}
] | Create a function 'convertStringToInt' that takes a string and converts it into an integer. | def convertStringToInt(string):
convertValue = int(string)
return convertValue | |
[
{
"role": "user",
"content": "Make a function in javascript that takes two parameters ``name1`` and ``name2`` and returns both of the names together with a dash between them.\n\nlet name1 = 'John', name2 = 'Smith';"
},
{
"role": "assistant",
"content": "function combineNames(name1, name2) {\n r... | Make a function in javascript that takes two parameters ``name1`` and ``name2`` and returns both of the names together with a dash between them. | let name1 = 'John', name2 = 'Smith'; | function combineNames(name1, name2) {
return name1 + '-' + name2;
} |
[
{
"role": "user",
"content": "Given two strings s1 and s2, how can you check if s2 is a substring of s1?\n\ns1 = \"testString\"\ns2 = \"String\""
},
{
"role": "assistant",
"content": "if s2 in s1:\n print(\"s2 is a substring of s1\")\nelse:\n print(\"s2 is not a substring of s1\")"
}
] | Given two strings s1 and s2, how can you check if s2 is a substring of s1? | s1 = "testString"
s2 = "String" | if s2 in s1:
print("s2 is a substring of s1")
else:
print("s2 is not a substring of s1") |
[
{
"role": "user",
"content": "Write a CSS rule to hide all elements with class \"hidden\"."
},
{
"role": "assistant",
"content": ".hidden {\n display: none;\n}"
}
] | Write a CSS rule to hide all elements with class "hidden". | .hidden {
display: none;
} | |
[
{
"role": "user",
"content": "Edit the code to add each item to a dictionary.\n\ndef add_to_dict(input_dict, key, value):\n return"
},
{
"role": "assistant",
"content": "def add_to_dict(input_dict, key, value):\n if key in input_dict:\n input_dict[key].append(value)\n else:\n ... | Edit the code to add each item to a dictionary. | def add_to_dict(input_dict, key, value):
return | def add_to_dict(input_dict, key, value):
if key in input_dict:
input_dict[key].append(value)
else:
input_dict[key] = [value]
return input_dict |
[
{
"role": "user",
"content": "Write a code to delete a 'customer' table from a MySQL database."
},
{
"role": "assistant",
"content": "# Delete 'customer' table from MySQL database\nimport mysql.connector\n\nmydb = mysql.connector.connect(\n host=\"localhost\",\n user=\"yourusername\",\n passw... | Write a code to delete a 'customer' table from a MySQL database. | # Delete 'customer' table from MySQL database
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="yourusername",
passwd="yourpassword",
database="mydatabase"
)
mycursor = mydb.cursor()
sql = "DROP TABLE customer"
mycursor.execute(sql) | |
[
{
"role": "user",
"content": "Given a text string modify it by capitalizing the letters after a period.\n\nhello world. this is from gpt"
},
{
"role": "assistant",
"content": "hello world. This is from GPT"
}
] | Given a text string modify it by capitalizing the letters after a period. | hello world. this is from gpt | hello world. This is from GPT |
[
{
"role": "user",
"content": "Given a string, convert all lowercase characters to uppercase.\n\nstr = 'hello World'"
},
{
"role": "assistant",
"content": "str.upper()"
}
] | Given a string, convert all lowercase characters to uppercase. | str = 'hello World' | str.upper() |
[
{
"role": "user",
"content": "Write a Python code snippet to check if an integer is between 5 and 10 (including both).\n\nx = 8"
},
{
"role": "assistant",
"content": "if 5 <= x <= 10:\n print('The integer is between 5 and 10.')\nelse:\n print('The integer is not between 5 and 10.')"
}
] | Write a Python code snippet to check if an integer is between 5 and 10 (including both). | x = 8 | if 5 <= x <= 10:
print('The integer is between 5 and 10.')
else:
print('The integer is not between 5 and 10.') |
[
{
"role": "user",
"content": "Construct an if-else statement to determine if a given number is divisible by 4"
},
{
"role": "assistant",
"content": "if (number % 4 == 0) \n System.out.println(\"The number is divisible by 4\"); \nelse \n System.out.println(\"The number is not divisible by 4... | Construct an if-else statement to determine if a given number is divisible by 4 | if (number % 4 == 0)
System.out.println("The number is divisible by 4");
else
System.out.println("The number is not divisible by 4"); | |
[
{
"role": "user",
"content": "Write an HTML code snippet for creating a search box."
},
{
"role": "assistant",
"content": "<form action=\"/search\" method=\"get\">\n <input name=\"s\" type=\"text\" placeholder=\"Search...\">\n <input type=\"submit\" value=\"Search\">\n</form>"
}
] | Write an HTML code snippet for creating a search box. | <form action="/search" method="get">
<input name="s" type="text" placeholder="Search...">
<input type="submit" value="Search">
</form> | |
[
{
"role": "user",
"content": "Generate a unique number from given two numbers.\n\nNumber 1: 12\nNumber 2: 24"
},
{
"role": "assistant",
"content": "num = str(12) + str(24)\nunique_num = int(num)"
}
] | Generate a unique number from given two numbers. | Number 1: 12
Number 2: 24 | num = str(12) + str(24)
unique_num = int(num) |
[
{
"role": "user",
"content": "Create an array of objects that contains the inventory of a store.\n\nInventory of a store:\n- Apple: 10\n- Orange: 20\n- Banana: 5\n- Grapes: 15"
},
{
"role": "assistant",
"content": "var inventory = [ \n {item: 'Apple', qty: 10}, \n {item: 'Orange', qty: 20}... | Create an array of objects that contains the inventory of a store. | Inventory of a store:
- Apple: 10
- Orange: 20
- Banana: 5
- Grapes: 15 | var inventory = [
{item: 'Apple', qty: 10},
{item: 'Orange', qty: 20},
{item: 'Banana', qty: 5},
{item: 'Grapes', qty: 15}
]; |
[
{
"role": "user",
"content": "Edit the following class to make sure any variables created as part of the class cannot be modified by the program\n\nclass Example:\n def __init__(self, x, y):\n self.x = x\n self.y = y"
},
{
"role": "assistant",
"content": "class Example:\n def... | Edit the following class to make sure any variables created as part of the class cannot be modified by the program | class Example:
def __init__(self, x, y):
self.x = x
self.y = y | class Example:
def __init__(self, x, y):
self.__x = x
self.__y = y
@property
def x(self):
return self.__x
@x.setter
def x(self, val):
raise AttributeError("Cannot modify x")
@property
def y(self):
return self.__y
@y.setter
def y(self, val):
... |
[
{
"role": "user",
"content": "Design a Python class to represent a rectangle with a length and width attribute."
},
{
"role": "assistant",
"content": "class Rectangle:\n def __init__(self, length, width):\n self.length = length\n self.width = width\n \n def get_area(self):... | Design a Python class to represent a rectangle with a length and width attribute. | class Rectangle:
def __init__(self, length, width):
self.length = length
self.width = width
def get_area(self):
return self.length*self.width | |
[
{
"role": "user",
"content": "Correct the following code in Java.\n\npublic class HelloWorld \n{\n public static Void main(String[] args) \n {\n System.out.println(\"Hello World!\"):\n }\n}"
},
{
"role": "assistant",
"content": "public class HelloWorld \n{\n public static void... | Correct the following code in Java. | public class HelloWorld
{
public static Void main(String[] args)
{
System.out.println("Hello World!"):
}
} | public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
} |
[
{
"role": "user",
"content": "Construct a regex pattern to match a valid IP address"
},
{
"role": "assistant",
"content": "^(((25[0–5]|2[0-4][0–9]|[01]?[0-9][0–9]?)\\.){3}(25[0–5]|2[0-4][0–9]|[01]?[0–9][0–9]?))$"
}
] | Construct a regex pattern to match a valid IP address | ^(((25[0–5]|2[0-4][0–9]|[01]?[0-9][0–9]?)\.){3}(25[0–5]|2[0-4][0–9]|[01]?[0–9][0–9]?))$ | |
[
{
"role": "user",
"content": "How many distinct prime numbers are there less than 100?"
},
{
"role": "assistant",
"content": "There are 25 distinct prime numbers less than 100."
}
] | How many distinct prime numbers are there less than 100? | There are 25 distinct prime numbers less than 100. | |
[
{
"role": "user",
"content": "Edit the following SQL statement to select all rows from the \"users\" table where the \"country_id\" is 2 and the \"level\" is greater than 5.\n\nSELECT * FROM users;"
},
{
"role": "assistant",
"content": "SELECT * FROM users\nWHERE country_id = 2 \nAND level > 5;"... | Edit the following SQL statement to select all rows from the "users" table where the "country_id" is 2 and the "level" is greater than 5. | SELECT * FROM users; | SELECT * FROM users
WHERE country_id = 2
AND level > 5; |
[
{
"role": "user",
"content": "Write an SQL query for fetching records from a table called 'Student'."
},
{
"role": "assistant",
"content": "SELECT * FROM Student;"
}
] | Write an SQL query for fetching records from a table called 'Student'. | SELECT * FROM Student; | |
[
{
"role": "user",
"content": "Given a document, remove all numbers from the content.\n\nHello! This is a test. There are 1, 2, 3 numbers here."
},
{
"role": "assistant",
"content": "Hello! This is a test. There are numbers here."
}
] | Given a document, remove all numbers from the content. | Hello! This is a test. There are 1, 2, 3 numbers here. | Hello! This is a test. There are numbers here. |
[
{
"role": "user",
"content": "What type of complexity will the following two sorting algorithms have?\n\nselection sort: O(n^2) \nbubble sort: O(n^2)"
},
{
"role": "assistant",
"content": "The selection sort algorithm will have a complexity of O(n^2). The bubble sort algorithm will also have a c... | What type of complexity will the following two sorting algorithms have? | selection sort: O(n^2)
bubble sort: O(n^2) | The selection sort algorithm will have a complexity of O(n^2). The bubble sort algorithm will also have a complexity of O(n^2). |
[
{
"role": "user",
"content": "Modify the following python program to include a comment explaining the purpose of the code\n\nnumbers = [1, 2, 3, 4, 5]\nsum = 0\nfor num in numbers:\n sum += num"
},
{
"role": "assistant",
"content": "# This program is used to calculate the sum of a given list ... | Modify the following python program to include a comment explaining the purpose of the code | numbers = [1, 2, 3, 4, 5]
sum = 0
for num in numbers:
sum += num | # This program is used to calculate the sum of a given list of numbers
numbers = [1, 2, 3, 4, 5]
sum = 0
for num in numbers:
sum += num |
[
{
"role": "user",
"content": "Given an array of integers and an integer value, figure out whether the given value is present in the array or not.\n\nArray: [1, 2, 3, 4, 5, 6]\nValue: 7"
},
{
"role": "assistant",
"content": "False"
}
] | Given an array of integers and an integer value, figure out whether the given value is present in the array or not. | Array: [1, 2, 3, 4, 5, 6]
Value: 7 | False |
[
{
"role": "user",
"content": "Generate a dictionary that contains all the words in a string of text, and the number of times each word occurs.\n\nText: \"I like dogs and cats and I like cats more than dogs\""
},
{
"role": "assistant",
"content": "def create_dict(text):\n text_list = text.split(... | Generate a dictionary that contains all the words in a string of text, and the number of times each word occurs. | Text: "I like dogs and cats and I like cats more than dogs" | def create_dict(text):
text_list = text.split(' ')
count_dict = {}
for word in text_list:
count_dict[word] = count_dict.get(word, 0) + 1
return count_dict |
[
{
"role": "user",
"content": "Calculate the total area of a circle given the radius.\n\nradius = 5"
},
{
"role": "assistant",
"content": "radius = 5\n\nimport math\n\n# calculate the area\narea = math.pi * radius ** 2\n\nprint(\"The total area of the circle is \"+str(area)) # prints The total ar... | Calculate the total area of a circle given the radius. | radius = 5 | radius = 5
import math
# calculate the area
area = math.pi * radius ** 2
print("The total area of the circle is "+str(area)) # prints The total area of the circle is 78.53981633974483 |
[
{
"role": "user",
"content": "Find the variable type for the following statement:\n\nname = \"John\""
},
{
"role": "assistant",
"content": "The variable type for the above statement is string."
}
] | Find the variable type for the following statement: | name = "John" | The variable type for the above statement is string. |
[
{
"role": "user",
"content": "Write a Java program to print the elements (i, j) of a two dimensional array.\n\nint[][] matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}"
},
{
"role": "assistant",
"content": "for (int i = 0; i < matrix.length; i++) {\n for (int j = 0; j < matrix[i].length; j++)\n ... | Write a Java program to print the elements (i, j) of a two dimensional array. | int[][] matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} | for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++)
System.out.print(matrix[i][j] + " ");
System.out.println();
} |
[
{
"role": "user",
"content": "Write a Java code to calculate the maximum value in an array."
},
{
"role": "assistant",
"content": "public static int getMax(int[] array) {\n int max = array[0];\n for (int i=1; i < array.length; i++) {\n if (array[i] > max) {\n max = array[i];\n }\n... | Write a Java code to calculate the maximum value in an array. | public static int getMax(int[] array) {
int max = array[0];
for (int i=1; i < array.length; i++) {
if (array[i] > max) {
max = array[i];
}
}
return max;
} | |
[
{
"role": "user",
"content": "Write code in Java to create a linked list."
},
{
"role": "assistant",
"content": "class Node{\n int data; \n Node next; \n \n Node(int d){\n data = d; \n next = null; \n } \n} \n\nclass LinkedList{ \n Node head; \n \n p... | Write code in Java to create a linked list. | class Node{
int data;
Node next;
Node(int d){
data = d;
next = null;
}
}
class LinkedList{
Node head;
public void insert(int data){
Node node = new Node(data);
if (head == null) {
head = node;
}
else {
... | |
[
{
"role": "user",
"content": "Create a basic login form in HTML."
},
{
"role": "assistant",
"content": "<form action=\"\" method=\"POST\">\n\n <div>\n <label for=\"username\">Username:</label>\n <input type=\"text\" name=\"username\" id=\"username\">\n </div>\n\n <div>\n <label for=\"password... | Create a basic login form in HTML. | <form action="" method="POST">
<div>
<label for="username">Username:</label>
<input type="text" name="username" id="username">
</div>
<div>
<label for="password">Password:</label>
<input type="password" name="password" id="password">
</div>
<button type="submit">Log In</button>
</form> | |
[
{
"role": "user",
"content": "Design a logic in Rust to check if an entered integer is a prime number or not."
},
{
"role": "assistant",
"content": "fn is_prime(number: i32) -> bool {\n if number == 0 || number == 1 {\n return false\n }\n for i in 2..(number/2) {\n if numb... | Design a logic in Rust to check if an entered integer is a prime number or not. | fn is_prime(number: i32) -> bool {
if number == 0 || number == 1 {
return false
}
for i in 2..(number/2) {
if number % i == 0 {
return false
}
}
return true
} | |
[
{
"role": "user",
"content": "Edit the following JavaScript to add validation to an input field.\n\n<input type=\"text\" id=\"name\" name=\"name\" />"
},
{
"role": "assistant",
"content": "<input type=\"text\" id=\"name\" name=\"name\" onChange=\"validateName()\" />\n\n<script>\nfunction validat... | Edit the following JavaScript to add validation to an input field. | <input type="text" id="name" name="name" /> | <input type="text" id="name" name="name" onChange="validateName()" />
<script>
function validateName() {
var name = document.getElementById("name").value;
if (name.length < 5) {
alert("Name should contain at least 5 characters!");
}
}
</script> |
[
{
"role": "user",
"content": "Develop a function in Python to convert a temperature in Celsius to Fahrenheit.\n\nTemperature in Celsius: 30"
},
{
"role": "assistant",
"content": "def celsius_to_fahrenheit(celsius):\n return (celsius * 1.8) + 32\n\nprint(celsius_to_fahrenheit(30))"
}
] | Develop a function in Python to convert a temperature in Celsius to Fahrenheit. | Temperature in Celsius: 30 | def celsius_to_fahrenheit(celsius):
return (celsius * 1.8) + 32
print(celsius_to_fahrenheit(30)) |
[
{
"role": "user",
"content": "Implement a Go program that takes a string as input and prints its reverse."
},
{
"role": "assistant",
"content": "package main\n\nimport \"fmt\"\n\nfunc main() {\n var str string\n fmt.Printf(\"Enter a string: \")\n fmt.Scanf(\"%s\\n\", &str)\n fmt.Prin... | Implement a Go program that takes a string as input and prints its reverse. | package main
import "fmt"
func main() {
var str string
fmt.Printf("Enter a string: ")
fmt.Scanf("%s\n", &str)
fmt.Printf("The reverse of the string is %s\n", reverse(str))
}
func reverse(s string) string {
r := []rune(s)
for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
r[i], r... | |
[
{
"role": "user",
"content": "Convert this program into an AsyncIO based one.\n\nimport time\n\ndef calculate_sum(numbers):\n result = 0\n for num in numbers:\n result += num\n time.sleep(2)\n return result"
},
{
"role": "assistant",
"content": "import asyncio\n\nasync def... | Convert this program into an AsyncIO based one. | import time
def calculate_sum(numbers):
result = 0
for num in numbers:
result += num
time.sleep(2)
return result | import asyncio
async def calculate_sum(numbers):
result = 0
for num in numbers:
result += num
await asyncio.sleep(2)
return result |
[
{
"role": "user",
"content": "Design an algorithm in Java to reverse a list of integers.\n\nlist = [1,2,3,4,5]"
},
{
"role": "assistant",
"content": "public static void reverseList(List<Integer> list) \n{\n Collections.reverse(list); \n}"
}
] | Design an algorithm in Java to reverse a list of integers. | list = [1,2,3,4,5] | public static void reverseList(List<Integer> list)
{
Collections.reverse(list);
} |
[
{
"role": "user",
"content": "Create a function in JavaScript that takes two temperatures and returns their average."
},
{
"role": "assistant",
"content": "function average_temperature(temp1, temp2) {\n return (temp1 + temp2) / 2;\n}"
}
] | Create a function in JavaScript that takes two temperatures and returns their average. | function average_temperature(temp1, temp2) {
return (temp1 + temp2) / 2;
} | |
[
{
"role": "user",
"content": "Write a lambda expression to find the maximum value of two numbers."
},
{
"role": "assistant",
"content": "maximum = lambda num1, num2: num1 if num1 > num2 else num2"
}
] | Write a lambda expression to find the maximum value of two numbers. | maximum = lambda num1, num2: num1 if num1 > num2 else num2 | |
[
{
"role": "user",
"content": "Which language is most suitable for creating a web page?"
},
{
"role": "assistant",
"content": "HTML is the language most suitable for creating a web page. It allows you to create the structure and content of the web page and can be combined with other languages suc... | Which language is most suitable for creating a web page? | HTML is the language most suitable for creating a web page. It allows you to create the structure and content of the web page and can be combined with other languages such as CSS and JavaScript to improve the look and feel of the web page. | |
[
{
"role": "user",
"content": "Create a Ruby script to loop through the items of a given array and print it on the command line.\n\nlist = [\"Apple\",\"Banana\",\"Orange\"]"
},
{
"role": "assistant",
"content": "list = [\"Apple\",\"Banana\",\"Orange\"]\n\nlist.each do |item|\n puts item\nend"
... | Create a Ruby script to loop through the items of a given array and print it on the command line. | list = ["Apple","Banana","Orange"] | list = ["Apple","Banana","Orange"]
list.each do |item|
puts item
end |
[
{
"role": "user",
"content": "How can I get the last element of this list?\n\nlist = [1, 2, 3, 4, 5]"
},
{
"role": "assistant",
"content": "The last element of the list can be accessed using the index -1 or using the list method pop(): \n\nlast_element = list[-1] \n\nor \n\nlast_element = list.p... | How can I get the last element of this list? | list = [1, 2, 3, 4, 5] | The last element of the list can be accessed using the index -1 or using the list method pop():
last_element = list[-1]
or
last_element = list.pop() |
[
{
"role": "user",
"content": "Create a Python function 'findPattern' with two parameters which takes two strings and returns 1 if the second string is a subsequence of the first string, otherwise 0."
},
{
"role": "assistant",
"content": "def findPattern(str1, str2): \n \n ind = 0\n for ch ... | Create a Python function 'findPattern' with two parameters which takes two strings and returns 1 if the second string is a subsequence of the first string, otherwise 0. | def findPattern(str1, str2):
ind = 0
for ch in str2:
if ch not in str1[ind:]:
return 0
ind = str1.index(ch, ind) + 1
return 1
# Driver code
if findPattern("timetopractice", "top"):
print("Subsequence Found")
else:
print("Subsequence Not Found") | |
[
{
"role": "user",
"content": "Create a function \"distance\" that takes two sets of coordinates in the form of [x1, y1] and [x2, y2] and computes the Euclidean distance between them."
},
{
"role": "assistant",
"content": "def distance(c1, c2):\n \"\"\"Function to calculate Euclidean distance ... | Create a function "distance" that takes two sets of coordinates in the form of [x1, y1] and [x2, y2] and computes the Euclidean distance between them. | def distance(c1, c2):
"""Function to calculate Euclidean distance between two sets of coordinates"""
x1, y1 = c1
x2, y2 = c2
return math.sqrt((x2 - x1)**2 + (y2 - y1)**2) | |
[
{
"role": "user",
"content": "What is an exception handling code in Python?"
},
{
"role": "assistant",
"content": "Exception handling in Python is a process in which errors or exceptions in a program are handled using certain programming construct such as try-except or try-finally blocks so that... | What is an exception handling code in Python? | Exception handling in Python is a process in which errors or exceptions in a program are handled using certain programming construct such as try-except or try-finally blocks so that the program can recover from such exceptions and continue running. Exception handling helps prevent critical errors in the program from cr... | |
[
{
"role": "user",
"content": "Generate a random string of 12 characters using Python."
},
{
"role": "assistant",
"content": "import string\nimport random\n\n''.join(random.choices(string.ascii_letters + string.digits, k=12))"
}
] | Generate a random string of 12 characters using Python. | import string
import random
''.join(random.choices(string.ascii_letters + string.digits, k=12)) | |
[
{
"role": "user",
"content": "Suggest an assembly instruction to move 1 byte of data from one register A to register B."
},
{
"role": "assistant",
"content": "movb A, B"
}
] | Suggest an assembly instruction to move 1 byte of data from one register A to register B. | movb A, B | |
[
{
"role": "user",
"content": "Using the given array, write a Javascript program to sort the elements in descending order.\n\nlet numbers = [2, 10, 5, 4, 3];"
},
{
"role": "assistant",
"content": "let numbers = [2, 10, 5, 4, 3];\nnumbers.sort((a,b) => b - a);\nconsole.log(numbers); //output: [10,... | Using the given array, write a Javascript program to sort the elements in descending order. | let numbers = [2, 10, 5, 4, 3]; | let numbers = [2, 10, 5, 4, 3];
numbers.sort((a,b) => b - a);
console.log(numbers); //output: [10, 5, 4, 3, 2] |
[
{
"role": "user",
"content": "Merge the two JSON objects into one object.\n\nObject 1:\n{\n \"name\": \"fruits\"\n \"data\": []\n}\nObject 2:\n{\n \"name\": \"vegetables\"\n \"data\": []\n}"
},
{
"role": "assistant",
"content": "{\n \"name\": [\"fruits\", \"vegetables\"],\n \"d... | Merge the two JSON objects into one object. | Object 1:
{
"name": "fruits"
"data": []
}
Object 2:
{
"name": "vegetables"
"data": []
} | {
"name": ["fruits", "vegetables"],
"data": []
} |
[
{
"role": "user",
"content": "Edit the following HTML code to display a border around the element with the ID 'test-element'.\n\n<div id=\"test-element\">Hello World</div>"
},
{
"role": "assistant",
"content": "<div id=\"test-element\" style=\"border:1px solid #000\">Hello World</div>"
}
] | Edit the following HTML code to display a border around the element with the ID 'test-element'. | <div id="test-element">Hello World</div> | <div id="test-element" style="border:1px solid #000">Hello World</div> |
[
{
"role": "user",
"content": "Design a classifier using Machine Learning in Python"
},
{
"role": "assistant",
"content": "import pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.ensemble import GradientBoostingClas... | Design a classifier using Machine Learning in Python | import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import GradientBoostingClassifier
# Load the data
data = pd.read_csv('data.csv')
# Split dataset into training and testing sets
X, y = data.iloc[:, 0: -1], data.iloc[:, -1]
X... | |
[
{
"role": "user",
"content": "Write a PHP program to receive an array as an input and return an array with the same elements in reverse order.\n\n[1, 2, 3, 4, 5]"
},
{
"role": "assistant",
"content": "<?php\n\nfunction reverse_array($arr) {\n $reversed_arr = array_reverse($arr);\n return $reve... | Write a PHP program to receive an array as an input and return an array with the same elements in reverse order. | [1, 2, 3, 4, 5] | <?php
function reverse_array($arr) {
$reversed_arr = array_reverse($arr);
return $reversed_arr;
}
$input_arr = [1, 2, 3, 4, 5];
$output_arr = reverse_array($input_arr);
print_r($output_arr); |
[
{
"role": "user",
"content": "Write an SQL query to select all records from a table named \"Employees\" and order the records by their salary in descending order."
},
{
"role": "assistant",
"content": "SELECT * FROM Employees ORDER BY Salary DESC;"
}
] | Write an SQL query to select all records from a table named "Employees" and order the records by their salary in descending order. | SELECT * FROM Employees ORDER BY Salary DESC; | |
[
{
"role": "user",
"content": "Modify and update the given HTML code to include a background color.\n\n<html>\n<head>\n <title>My Page</title>\n</head>\n<body>\n <h1>My Page</h1>\n</body>\n</html>"
},
{
"role": "assistant",
"content": "<html>\n<head>\n <title>My Page</title>\n</head>\n<body st... | Modify and update the given HTML code to include a background color. | <html>
<head>
<title>My Page</title>
</head>
<body>
<h1>My Page</h1>
</body>
</html> | <html>
<head>
<title>My Page</title>
</head>
<body style="background-color: #FFFFFF;">
<h1>My Page</h1>
</body>
</html> |
[
{
"role": "user",
"content": "What do the following two lines of code do?\n\nstring.replace('old', 'new')\nstring.rstrip()"
},
{
"role": "assistant",
"content": "The first line of code is used to replace all occurrences of \"old\" with \"new\" in string. The second line of code is used to strip ... | What do the following two lines of code do? | string.replace('old', 'new')
string.rstrip() | The first line of code is used to replace all occurrences of "old" with "new" in string. The second line of code is used to strip all trailing whitespace from the string. |
[
{
"role": "user",
"content": "You need to design a calculator class with methods to perform basic calculations (add, subtract, multiply, divide, etc.)."
},
{
"role": "assistant",
"content": "class Calculator:\n def __init__(self):\n # initializing the calculator\n pass\n\n de... | You need to design a calculator class with methods to perform basic calculations (add, subtract, multiply, divide, etc.). | class Calculator:
def __init__(self):
# initializing the calculator
pass
def add(self, a, b):
return a + b
def subtract(self, a, b):
return a - b
def multiply(self, a, b):
return a * b
def divide(self, a, b):
return a / b | |
[
{
"role": "user",
"content": "Write an HTML page that displays a single line of text saying \"Hello World\"."
},
{
"role": "assistant",
"content": "<html>\n <head>\n <title>Hello World</title>\n </head>\n <body>\n <p>Hello World</p>\n </body>\n</html>"
}
] | Write an HTML page that displays a single line of text saying "Hello World". | <html>
<head>
<title>Hello World</title>
</head>
<body>
<p>Hello World</p>
</body>
</html> | |
[
{
"role": "user",
"content": "Write a SQL query to show the 20 most common car makes in a given table.\n\nCars Table\n\n| make | model | year |\n|----------|-------|------|\n| Honda | Civic | 2019 |\n| Ford | F150 | 2018 |\n| Toyota | Camry | 2017 |\n| Chevrolet| Cruze | 2016 |"
},
{
"... | Write a SQL query to show the 20 most common car makes in a given table. | Cars Table
| make | model | year |
|----------|-------|------|
| Honda | Civic | 2019 |
| Ford | F150 | 2018 |
| Toyota | Camry | 2017 |
| Chevrolet| Cruze | 2016 | | SELECT make, COUNT(*)
FROM Cars
GROUP BY make
ORDER BY COUNT(*) DESC
LIMIT 20 |
[
{
"role": "user",
"content": "Generate a correct Python code for a data structure which supports the following operations -\n\ninsert(key, value)\nget(key)\ndelete(key)"
},
{
"role": "assistant",
"content": "class Map(object):\n \n def __init__(self): \n # a dictionary-based data st... | Generate a correct Python code for a data structure which supports the following operations - | insert(key, value)
get(key)
delete(key) | class Map(object):
def __init__(self):
# a dictionary-based data structure
# to store (key, value) pairs
self.data = {}
# insert the given value with the given key
def insert(self, key, value):
self.data[key] = value
# get the value for the given key... |
[
{
"role": "user",
"content": "Suggest a completion for the following code to check if the given string is a palindrome.\n\nstring = 'malayalam'"
},
{
"role": "assistant",
"content": "rev_str = string[::-1]\nif rev_str == string:\n print(\"The string is a palindrome.\")"
}
] | Suggest a completion for the following code to check if the given string is a palindrome. | string = 'malayalam' | rev_str = string[::-1]
if rev_str == string:
print("The string is a palindrome.") |
[
{
"role": "user",
"content": "Create an HTML page that has two paragraphs, a heading and a link to a website.\n\nLink: https://example.com\nHeading: Example Website\nParagraph 1: This is the first paragraph.\nParagraph 2: This is the second paragraph."
},
{
"role": "assistant",
"content": "<html... | Create an HTML page that has two paragraphs, a heading and a link to a website. | Link: https://example.com
Heading: Example Website
Paragraph 1: This is the first paragraph.
Paragraph 2: This is the second paragraph. | <html>
<head>
<title>Example Website</title>
</head>
<body>
<h1>Example Website<h1>
<p>This is the first paragraph.</p>
<p>This is the second paragraph.</p>
<a href="https://example.com">Link to Website</a>
</body>
</html> |
[
{
"role": "user",
"content": "Convert a given 2D point to the polar representation.\n\nPoint: (1,1)"
},
{
"role": "assistant",
"content": "def polar_rep(point):\n x, y = point\n r = math.sqrt(x**2 + y**2) \n theta = math.atan2(y, x)\n return (r, theta)"
}
] | Convert a given 2D point to the polar representation. | Point: (1,1) | def polar_rep(point):
x, y = point
r = math.sqrt(x**2 + y**2)
theta = math.atan2(y, x)
return (r, theta) |
[
{
"role": "user",
"content": "Write a C++ program that calculates the sum of consecutive numbers from 1 to 10."
},
{
"role": "assistant",
"content": "#include <iostream>\n\nint main() {\n int sum = 0;\n \n for (int i = 1; i <= 10; i++) {\n sum += i;\n }\n \n std::cout << \"Sum of consecutive nu... | Write a C++ program that calculates the sum of consecutive numbers from 1 to 10. | #include <iostream>
int main() {
int sum = 0;
for (int i = 1; i <= 10; i++) {
sum += i;
}
std::cout << "Sum of consecutive number from 1 to 10 is " << sum << std::endl;
return 0;
} | |
[
{
"role": "user",
"content": "Merge two sorted lists into a single sorted list\n\nlist1 = [1,3,5,7] \nlist2 = [2,4,6,8]"
},
{
"role": "assistant",
"content": "def merge_sorted_lists(list1, list2):\n merged_list = []\n i = 0\n j = 0\n\n # Iterate through the lists until all elements h... | Merge two sorted lists into a single sorted list | list1 = [1,3,5,7]
list2 = [2,4,6,8] | def merge_sorted_lists(list1, list2):
merged_list = []
i = 0
j = 0
# Iterate through the lists until all elements have been merged
while (i < len(list1) and j < len(list2)):
# If the element from the first list is smaller, add it
# to the merged list
if list1[i] < list2[j]:... |
[
{
"role": "user",
"content": "Construct a for-loop to print all numbers from 1 to n, separated by a space."
},
{
"role": "assistant",
"content": "for i in range(1, n + 1):\n print(i, end=\" \")"
}
] | Construct a for-loop to print all numbers from 1 to n, separated by a space. | for i in range(1, n + 1):
print(i, end=" ") | |
[
{
"role": "user",
"content": "Write a Java program to sum the elements of an array except for the maximum and minimum.\n\nArray: [1, 2, 3, 4, 5]"
},
{
"role": "assistant",
"content": "class Sum {\n public static void main(String[] args) {\n int[] arr = {1,2,3,4,5};\n int max = a... | Write a Java program to sum the elements of an array except for the maximum and minimum. | Array: [1, 2, 3, 4, 5] | class Sum {
public static void main(String[] args) {
int[] arr = {1,2,3,4,5};
int max = arr[0];
int min = arr[0];
int sum = 0;
for (int i = 0; i < arr.length; i++) {
sum += arr[i];
if (arr[i] > max) {
max = arr[i];
... |
[
{
"role": "user",
"content": "You need to create a dictionary that contains five elements with their associated values."
},
{
"role": "assistant",
"content": "myDictionary = {\n 'apple': 'fruit',\n 'celery': 'vegetable',\n 'sun': 'star',\n 'earth': 'planet',\n 'light': 'energy'\n}"
}
] | You need to create a dictionary that contains five elements with their associated values. | myDictionary = {
'apple': 'fruit',
'celery': 'vegetable',
'sun': 'star',
'earth': 'planet',
'light': 'energy'
} | |
[
{
"role": "user",
"content": "Create a web page with all the elements aligned on the right, using only CSS."
},
{
"role": "assistant",
"content": "<style> \n * { \n text-align: right; \n } \n</style>"
}
] | Create a web page with all the elements aligned on the right, using only CSS. | <style>
* {
text-align: right;
}
</style> | |
[
{
"role": "user",
"content": "Construct a SQL query to find out three most expensive items in a product table."
},
{
"role": "assistant",
"content": "SELECT item_name, price FROM products ORDER BY price DESC LIMIT 3;"
}
] | Construct a SQL query to find out three most expensive items in a product table. | SELECT item_name, price FROM products ORDER BY price DESC LIMIT 3; | |
[
{
"role": "user",
"content": "Write a C# class that allows a user to enter a set of numbers and add them up."
},
{
"role": "assistant",
"content": "public class NumberAdder {\n\n int sum = 0; \n \n // Method to add the given numbers\n public void addNumbers(int[] numbers) {\n fo... | Write a C# class that allows a user to enter a set of numbers and add them up. | public class NumberAdder {
int sum = 0;
// Method to add the given numbers
public void addNumbers(int[] numbers) {
for (int i = 0; i < numbers.Length; i++){
this.sum += numbers[i];
}
}
} | |
[
{
"role": "user",
"content": "Provide a syntax for an if-else statement in Javascript."
},
{
"role": "assistant",
"content": "if (condition) {\n // statements when condition is true\n} else {\n // statements when condition is false\n}"
}
] | Provide a syntax for an if-else statement in Javascript. | if (condition) {
// statements when condition is true
} else {
// statements when condition is false
} | |
[
{
"role": "user",
"content": "Write a code in C++ to print the elements of a given array of strings using a for loop."
},
{
"role": "assistant",
"content": "#include <iostream>\n\nvoid printArray(std::string arr[], int n) \n{ \n for (int i = 0; i < n; i++) \n std::cout << arr[i] << std... | Write a code in C++ to print the elements of a given array of strings using a for loop. | #include <iostream>
void printArray(std::string arr[], int n)
{
for (int i = 0; i < n; i++)
std::cout << arr[i] << std::endl;
}
int main(){
std::string arr[] = {"one", "two", "three"};
int n = sizeof(arr) / sizeof(arr[0]);
printArray(arr, n);
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.