messages listlengths 2 2 | instruction stringlengths 14 288 | input stringlengths 0 635 | output stringlengths 1 3.91k |
|---|---|---|---|
[
{
"role": "user",
"content": "Implement a main method for the following abstract class.\n\nabstract class AbstractClass {\n\n abstract void funOne();\n\n abstract void funTwo();\n\n}"
},
{
"role": "assistant",
"content": "abstract class AbstractClass {\n\n abstract void funOne();\n\n ... | Implement a main method for the following abstract class. | abstract class AbstractClass {
abstract void funOne();
abstract void funTwo();
} | abstract class AbstractClass {
abstract void funOne();
abstract void funTwo();
public static void main(String[] args) {
// Code goes here
}
} |
[
{
"role": "user",
"content": "Write an SQL query to select all rows from the table 'users' where the 'last_name' is 'Smith'."
},
{
"role": "assistant",
"content": "SELECT * FROM users WHERE last_name = 'Smith'"
}
] | Write an SQL query to select all rows from the table 'users' where the 'last_name' is 'Smith'. | SELECT * FROM users WHERE last_name = 'Smith' | |
[
{
"role": "user",
"content": "How can a JavaScript function return multiple values?"
},
{
"role": "assistant",
"content": "A JavaScript function can return multiple values by using an array or an object. For example, the following example returns two values in an array: return [value1, value2];.... | How can a JavaScript function return multiple values? | A JavaScript function can return multiple values by using an array or an object. For example, the following example returns two values in an array: return [value1, value2];. Similarly, an object can be used to return multiple values, for example: return { value1: val1, value2: val2 };. | |
[
{
"role": "user",
"content": "Write a code to generate 1000 random numbers and print the mean of these random numbers."
},
{
"role": "assistant",
"content": "# Import the random module\nimport random\n\n# Generate 1000 random numbers \nrandom_numbers = [random.randint(1, 1000) for i in range(100... | Write a code to generate 1000 random numbers and print the mean of these random numbers. | # Import the random module
import random
# Generate 1000 random numbers
random_numbers = [random.randint(1, 1000) for i in range(1000)]
# Calculate mean of the random numbers
mean = sum(random_numbers)/len(random_numbers)
# Print mean of random numbers
print("The mean of 1000 random numbers is: ", mean) | |
[
{
"role": "user",
"content": "Write an R code to get the names of all uncorrelated columns in a data frame."
},
{
"role": "assistant",
"content": "# Get all column names\nall_columns <- names(data_frame)\n\n# Create an empty vector\nuncorrelated_columns <- c()\n# Iterate each column name in the ... | Write an R code to get the names of all uncorrelated columns in a data frame. | # Get all column names
all_columns <- names(data_frame)
# Create an empty vector
uncorrelated_columns <- c()
# Iterate each column name in the data_frame
for(column_name in all_columns) {
# Store the correlations of each column in a vector
correlations <- cor(data_frame[column_name], data_frame[-column_name])
# ... | |
[
{
"role": "user",
"content": "Construct a regex in Java that matches a valid email address."
},
{
"role": "assistant",
"content": "String regex = \"^[\\\\w-_\\\\.+]*[\\\\w-_\\\\.]\\\\@([\\\\w]+\\\\.)+[\\\\w]+[\\\\w]$\";"
}
] | Construct a regex in Java that matches a valid email address. | String regex = "^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$"; | |
[
{
"role": "user",
"content": "What is the output of this Java program?\n\npublic class Main {\n public static void main(String [] args) {\n String name = \"John\";\n int age = 34;\n System.out.println(\"My name is \" + name + \" and I am \" + age + \" years old.\");\n }\n}"
},
... | What is the output of this Java program? | public class Main {
public static void main(String [] args) {
String name = "John";
int age = 34;
System.out.println("My name is " + name + " and I am " + age + " years old.");
}
} | My name is John and I am 34 years old. |
[
{
"role": "user",
"content": "Identify the bugs in the following python code and fix them.\n\ndef multiply_dicts(d1, d2):\n for key in d1:\n d1[key] = d2[d1[key]]"
},
{
"role": "assistant",
"content": "def multiply_dicts(d1, d2):\n for key in d1:\n if key in d2:\n ... | Identify the bugs in the following python code and fix them. | def multiply_dicts(d1, d2):
for key in d1:
d1[key] = d2[d1[key]] | def multiply_dicts(d1, d2):
for key in d1:
if key in d2:
d1[key] = d2[key] |
[
{
"role": "user",
"content": "Write a regular expression to match the string \"123 Main Street\"."
},
{
"role": "assistant",
"content": "regex = r\"^\\d{3}\\s[A-Za-z]+\\s[A-Za-z]+$\""
}
] | Write a regular expression to match the string "123 Main Street". | regex = r"^\d{3}\s[A-Za-z]+\s[A-Za-z]+$" | |
[
{
"role": "user",
"content": "Create a Mastermind game in any language of your choice."
},
{
"role": "assistant",
"content": "#include <iostream>\n#include <vector>\n#include <cstdlib>\n#include <ctime>\n \nusing namespace std;\n \nint main() {\n \nsrand(time(0));\n \n//define random numbers to ... | Create a Mastermind game in any language of your choice. | #include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
srand(time(0));
//define random numbers to be guessed
int max_limit = 6;
vector<int> ans;
for (int i = 0; i < 4; i++) {
ans.push_back((rand() % max_limit) + 1);
}
int attempts = 0;
while (true) {
//Ta... | |
[
{
"role": "user",
"content": "Create a web page that displays a greeting using HTML"
},
{
"role": "assistant",
"content": "<!doctype html>\n<html>\n <head>\n <title>Greeting</title>\n </head>\n <body>\n <h1>Hello World!</h1>\n </body>\n</html>"
}
] | Create a web page that displays a greeting using HTML | <!doctype html>
<html>
<head>
<title>Greeting</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html> | |
[
{
"role": "user",
"content": "Write a code to filter the even numbers from the following array:\n\nmy_array = [1,2,3,4,5,6]"
},
{
"role": "assistant",
"content": "even_numbers = []\nfor number in my_array:\n if number % 2 == 0:\n even_numbers.append(number)\n\nprint(even_numbers)"
}
... | Write a code to filter the even numbers from the following array: | my_array = [1,2,3,4,5,6] | even_numbers = []
for number in my_array:
if number % 2 == 0:
even_numbers.append(number)
print(even_numbers) |
[
{
"role": "user",
"content": "Create a function that takes an array as input and returns true if all elements in the array are similarly oriented (i.e. either all positive or all negative).\n\n[-2, -4, -7, -9]"
},
{
"role": "assistant",
"content": "def is_all_same_sign(arr):\n is_same_sign = ... | Create a function that takes an array as input and returns true if all elements in the array are similarly oriented (i.e. either all positive or all negative). | [-2, -4, -7, -9] | def is_all_same_sign(arr):
is_same_sign = True
for i in range(len(arr)):
if i == 0:
sign = (arr[i] >= 0)
else:
if (arr[i] < 0) != sign:
is_same_sign = False
return is_same_sign |
[
{
"role": "user",
"content": "Look at the given code and find the bug in it.\n\ndef add_numbers(x,y):\n return x + y + 1"
},
{
"role": "assistant",
"content": "The bug in the given code is that it adds 1 extra to the result of the function. To fix this, the return statement should be modified... | Look at the given code and find the bug in it. | def add_numbers(x,y):
return x + y + 1 | The bug in the given code is that it adds 1 extra to the result of the function. To fix this, the return statement should be modified to: return x + y. |
[
{
"role": "user",
"content": "Determine and output the last occurence of the given number in an array.\n\nlet my_array = [2, 4, 8, 6, 2];\nlet my_number = 2;"
},
{
"role": "assistant",
"content": "let index = my_array.lastIndexOf(my_number);\nconsole.log(index);"
}
] | Determine and output the last occurence of the given number in an array. | let my_array = [2, 4, 8, 6, 2];
let my_number = 2; | let index = my_array.lastIndexOf(my_number);
console.log(index); |
[
{
"role": "user",
"content": "Write a HTML code snippet to create a link which redirects to a given website."
},
{
"role": "assistant",
"content": "<a href=\"https://www.example.com/\">Link Text</a>"
}
] | Write a HTML code snippet to create a link which redirects to a given website. | <a href="https://www.example.com/">Link Text</a> | |
[
{
"role": "user",
"content": "Create a function in Python to add two numbers, which may take any number of arguments."
},
{
"role": "assistant",
"content": "def add(*nums):\n \"\"\"Add two or more numbers.\"\"\"\n # Initialize sum\n result = 0\n\n # Iterate through given numbers\n ... | Create a function in Python to add two numbers, which may take any number of arguments. | def add(*nums):
"""Add two or more numbers."""
# Initialize sum
result = 0
# Iterate through given numbers
for num in nums:
result += num
# Return the sum
return result
# Example
sum = add(15, 7, 10)
print(sum)
# Output: 32 | |
[
{
"role": "user",
"content": "Write a JavaScript expression to check whether the string \"Hello World\" is present in another string.\n\nvar test_str = \"Hello World is a popular phrase\";"
},
{
"role": "assistant",
"content": "test_str.includes(\"Hello World\");"
}
] | Write a JavaScript expression to check whether the string "Hello World" is present in another string. | var test_str = "Hello World is a popular phrase"; | test_str.includes("Hello World"); |
[
{
"role": "user",
"content": "Given two equations, predict the range of the output variable.\n\nEquation 1: Y = X + 2\nEquation 2: Y = 2X"
},
{
"role": "assistant",
"content": "The range of the output variable is [-2, ∞)."
}
] | Given two equations, predict the range of the output variable. | Equation 1: Y = X + 2
Equation 2: Y = 2X | The range of the output variable is [-2, ∞). |
[
{
"role": "user",
"content": "Calculate the distance between two points (x1, y1) and (x2, y2).\n\nx1 = 5, x2 = 8\ny1 = 3, y2 = 12"
},
{
"role": "assistant",
"content": "def calculate_distance(x1, x2, y1, y2):\n return ((x2-x1)**2 + (y2-y1)**2)**0.5\n \ncalculate_distance(x1, x2, y1, y2)\n7... | Calculate the distance between two points (x1, y1) and (x2, y2). | x1 = 5, x2 = 8
y1 = 3, y2 = 12 | def calculate_distance(x1, x2, y1, y2):
return ((x2-x1)**2 + (y2-y1)**2)**0.5
calculate_distance(x1, x2, y1, y2)
7.615773105863909 |
[
{
"role": "user",
"content": "Create a dictionary with three items of your choice"
},
{
"role": "assistant",
"content": "{\n 'apple': 'fruit',\n 'carrot': 'vegetable',\n 'sugar': 'sweetener'\n}"
}
] | Create a dictionary with three items of your choice | {
'apple': 'fruit',
'carrot': 'vegetable',
'sugar': 'sweetener'
} | |
[
{
"role": "user",
"content": "Construct a program to remove leading zeros from a string.\n\n'00abc'"
},
{
"role": "assistant",
"content": "def remove_leading_zeros(str):\n return str.lstrip('0')"
}
] | Construct a program to remove leading zeros from a string. | '00abc' | def remove_leading_zeros(str):
return str.lstrip('0') |
[
{
"role": "user",
"content": "Design an efficient algorithm to search for an item in an array."
},
{
"role": "assistant",
"content": "One efficient algorithm to search for an item in an array is the binary search algorithm. The binary search algorithm works by dividing the array into two parts a... | Design an efficient algorithm to search for an item in an array. | One efficient algorithm to search for an item in an array is the binary search algorithm. The binary search algorithm works by dividing the array into two parts and then searching through the divided parts in logarithmic time. The algorithm starts by comparing the item to be searched with the middle element of the arra... | |
[
{
"role": "user",
"content": "Fix the bug in the following Python script:\n\ndef is_odd(x):\n if x % 2 == 1\n return True\n\nis_odd(5)"
},
{
"role": "assistant",
"content": "def is_odd(x):\n if x % 2 == 1:\n return True\n else:\n return False\n\nis_odd(5)"
}
] | Fix the bug in the following Python script: | def is_odd(x):
if x % 2 == 1
return True
is_odd(5) | def is_odd(x):
if x % 2 == 1:
return True
else:
return False
is_odd(5) |
[
{
"role": "user",
"content": "Multiply every element of a list and print the result.\n\nmyList = [3, 4, 5]"
},
{
"role": "assistant",
"content": "mulp = 1\nfor i in myList:\n mulp = mulp * i\nprint(mulp)"
}
] | Multiply every element of a list and print the result. | myList = [3, 4, 5] | mulp = 1
for i in myList:
mulp = mulp * i
print(mulp) |
[
{
"role": "user",
"content": "Create a Django model class to represent a User."
},
{
"role": "assistant",
"content": "from django.db import models\n\nclass User(models.Model):\n first_name = models.CharField(max_length=50)\n last_name = models.CharField(max_length=50)\n email = models.E... | Create a Django model class to represent a User. | from django.db import models
class User(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
email = models.EmailField(unique=True)
birth_date = models.DateField()
is_active = models.BooleanField(default=True)
created_at = models.DateTimeField(... | |
[
{
"role": "user",
"content": "Write a JavaScript program to find the remainder when two given numbers are divided.\n\n9 and 5"
},
{
"role": "assistant",
"content": "let dividend = 9;\nlet divisor = 5;\nlet remainder = dividend % divisor;\nconsole.log(remainder);"
}
] | Write a JavaScript program to find the remainder when two given numbers are divided. | 9 and 5 | let dividend = 9;
let divisor = 5;
let remainder = dividend % divisor;
console.log(remainder); |
[
{
"role": "user",
"content": "Write a function that returns the larger number from two numbers provided.\n\n4, 5"
},
{
"role": "assistant",
"content": "def largest(a, b):\n \"\"\"Returns the larger number from two numbers provided.\"\"\"\n if a > b:\n return a\n else:\n re... | Write a function that returns the larger number from two numbers provided. | 4, 5 | def largest(a, b):
"""Returns the larger number from two numbers provided."""
if a > b:
return a
else:
return b
num1 = 4
num2 = 5
print(largest(num1, num2)) |
[
{
"role": "user",
"content": "Change the last line of the code to assign a list value to the variable x.\n\nx = None"
},
{
"role": "assistant",
"content": "x = []"
}
] | Change the last line of the code to assign a list value to the variable x. | x = None | x = [] |
[
{
"role": "user",
"content": "Rewrite this code into Python.\n\nArrayList<Integer> arr = new ArrayList<>();\nfor (int i = 0; i < 10; i++) {\n arr.add(i);\n}\n\nint sum = 0;\nfor(int num : arr){\n sum += num;\n}"
},
{
"role": "assistant",
"content": "arr = []\nfor i in range(10):\n arr.a... | Rewrite this code into Python. | ArrayList<Integer> arr = new ArrayList<>();
for (int i = 0; i < 10; i++) {
arr.add(i);
}
int sum = 0;
for(int num : arr){
sum += num;
} | arr = []
for i in range(10):
arr.append(i)
sum = 0
for num in arr:
sum += num |
[
{
"role": "user",
"content": "Search for Usernames starting with “John” in the database."
},
{
"role": "assistant",
"content": "SELECT * FROM users WHERE username LIKE 'John%';"
}
] | Search for Usernames starting with “John” in the database. | SELECT * FROM users WHERE username LIKE 'John%'; | |
[
{
"role": "user",
"content": "Print all unique combinations of an array of integers\n\nnums = [1,2,3]"
},
{
"role": "assistant",
"content": "# Print all unique combinations of an array of integers\n\ndef all_combinations(nums):\n result = [[]]\n for num in nums:\n temp_result = []\n for ... | Print all unique combinations of an array of integers | nums = [1,2,3] | # Print all unique combinations of an array of integers
def all_combinations(nums):
result = [[]]
for num in nums:
temp_result = []
for res in result:
temp_result.append(res + [num])
result.extend(temp_result)
return result
print(all_combinations(nums)) # [[1], [2], [3], [1, 2], [1, 3], [2, 3]... |
[
{
"role": "user",
"content": "Rearrange the code to print the hierarchy of students in a Python class\n\nstudents = [\n {\n \"name\": \"John Smith\",\n \"role\": \"student\"\n },\n {\n \"name\": \"Alice Johnson\",\n \"role\": \"student\"\n },\n {\n \"name\": \"Bob Williams\",\n \"role... | Rearrange the code to print the hierarchy of students in a Python class | students = [
{
"name": "John Smith",
"role": "student"
},
{
"name": "Alice Johnson",
"role": "student"
},
{
"name": "Bob Williams",
"role": "teacher"
},
{
"name": "Cecilia Brown",
"role": "teacher"
}
] | students = [
{
"name": "John Smith",
"role": "student"
},
{
"name": "Alice Johnson",
"role": "student"
},
{
"name": "Bob Williams",
"role": "teacher"
},
{
"name": "Cecilia Brown",
"role": "teacher"
}
]
teachers = []
students_list = []
for student in students:
if stude... |
[
{
"role": "user",
"content": "Generate a query in SQL which can retrieve the maximum price for each product."
},
{
"role": "assistant",
"content": "SELECT product_id, MAX(price)\nFROM product_table\nGROUP BY product_id;"
}
] | Generate a query in SQL which can retrieve the maximum price for each product. | SELECT product_id, MAX(price)
FROM product_table
GROUP BY product_id; | |
[
{
"role": "user",
"content": "Suggest a method in Python for sorting a list of strings on the basis of their length in ascending order."
},
{
"role": "assistant",
"content": "We can use the built-in sorted() function to sort the list of strings on the basis of their length in ascending order. Th... | Suggest a method in Python for sorting a list of strings on the basis of their length in ascending order. | We can use the built-in sorted() function to sort the list of strings on the basis of their length in ascending order. The syntax for sorting is as follows:
sorted(list_of_strings, key=len)
where 'list_of_strings' is the list of strings we want to sort and 'len' is the length function for getting the length of each s... | |
[
{
"role": "user",
"content": "Given a list of integers, write a function that will return the largest sum of any two consecutive integers in the list.\n\n[7, 2, 5, 3]"
},
{
"role": "assistant",
"content": "def largest_sum_of_consecutive_ints(arr):\n largest_sum = 0\n for i in range(len(arr... | Given a list of integers, write a function that will return the largest sum of any two consecutive integers in the list. | [7, 2, 5, 3] | def largest_sum_of_consecutive_ints(arr):
largest_sum = 0
for i in range(len(arr)):
if i < len(arr)-1:
current_sum = arr[i] + arr[i+1]
largest_sum = max(largest_sum, current_sum)
return largest_sum |
[
{
"role": "user",
"content": "Determine the sum of the squares of all even numbers in a given array.\n\n[1, 2, 3, 4, 5, 6]"
},
{
"role": "assistant",
"content": "int sum = 0;\nfor (int i = 0; i < array.length; i++){\n if (array[i] % 2 == 0){\n sum += Math.pow(array[i], 2);\n }\n}\nr... | Determine the sum of the squares of all even numbers in a given array. | [1, 2, 3, 4, 5, 6] | int sum = 0;
for (int i = 0; i < array.length; i++){
if (array[i] % 2 == 0){
sum += Math.pow(array[i], 2);
}
}
return sum; |
[
{
"role": "user",
"content": "Convert a given JSON string to its Python dictionary equivalent.\n\njson_string = '{\"name\":\"John\",\"age\":30}'"
},
{
"role": "assistant",
"content": "import json\npython_dict = json.loads(json_string)"
}
] | Convert a given JSON string to its Python dictionary equivalent. | json_string = '{"name":"John","age":30}' | import json
python_dict = json.loads(json_string) |
[
{
"role": "user",
"content": "Write a code to create a FizzBuzz game, that prints the numbers from 1 to 50, replacing all the numbers divisible by 3 with the word \"Fizz\" and the numbers divisible by 5 with the word \"Buzz\"."
},
{
"role": "assistant",
"content": "\"\"\"\nWrite a code to create... | Write a code to create a FizzBuzz game, that prints the numbers from 1 to 50, replacing all the numbers divisible by 3 with the word "Fizz" and the numbers divisible by 5 with the word "Buzz". | """
Write a code to create a FizzBuzz game
"""
def fizz_buzz():
for i in range(1, 51):
if i % 3 == 0 and i % 5 == 0:
print("FizzBuzz")
elif i % 3 == 0:
print("Fizz")
elif i % 5 == 0:
print("Buzz")
else:
print(i)
if __name__ == '__main... | |
[
{
"role": "user",
"content": "You need to read a list of strings, split each into 2 substrings, and output the 2 substrings as a tuple.\n\n['international', 'imagination', 'skyscraper']"
},
{
"role": "assistant",
"content": "def split_words(string_list):\n new_list = []\n for string in str... | You need to read a list of strings, split each into 2 substrings, and output the 2 substrings as a tuple. | ['international', 'imagination', 'skyscraper'] | def split_words(string_list):
new_list = []
for string in string_list:
mid = int(len(string)/2)
new_list.append( (string[:mid], string[mid:]) )
return new_list |
[
{
"role": "user",
"content": "Convert the following list of URLs to strings without the protocol portions.\n\nurl_list = ['http://example.com/index', 'https://example.net/contact', \n 'http://example.org/about']"
},
{
"role": "assistant",
"content": "def convert_urls(url_list):\n r... | Convert the following list of URLs to strings without the protocol portions. | url_list = ['http://example.com/index', 'https://example.net/contact',
'http://example.org/about'] | def convert_urls(url_list):
return list(map(lambda x : x.split('://')[1] , url_list))
converted_urls = convert_urls(url_list)
print(converted_urls)
# Output: ['example.com/index', 'example.net/contact', 'example.org/about'] |
[
{
"role": "user",
"content": "Write an SQL query to select the \"name\" and \"salary\" columns of all employees with salary greater than 10000.\n\nTable name: employees"
},
{
"role": "assistant",
"content": "SELECT name, salary FROM employees\nWHERE salary > 10000;"
}
] | Write an SQL query to select the "name" and "salary" columns of all employees with salary greater than 10000. | Table name: employees | SELECT name, salary FROM employees
WHERE salary > 10000; |
[
{
"role": "user",
"content": "Find the length of a given string using JavaScript.\n\nstr = \"I'm a GPT model\""
},
{
"role": "assistant",
"content": "let str = \"I'm a GPT model\";\nlet length = str.length;\nconsole.log(length); // 16"
}
] | Find the length of a given string using JavaScript. | str = "I'm a GPT model" | let str = "I'm a GPT model";
let length = str.length;
console.log(length); // 16 |
[
{
"role": "user",
"content": "Generate a string array of length 10, containing only alphabets in lower case containing 10 random characters."
},
{
"role": "assistant",
"content": "import random\ndef gen_string_arr(n):\n output = []\n for i in range(n):\n output.append(''.join(random... | Generate a string array of length 10, containing only alphabets in lower case containing 10 random characters. | import random
def gen_string_arr(n):
output = []
for i in range(n):
output.append(''.join(random.choices('abcdefghijklmnopqrstuvwxyz', k=10)))
return output | |
[
{
"role": "user",
"content": "Using HTML and CSS, create a page layout with two columns and a header row."
},
{
"role": "assistant",
"content": "<html>\n <head>\n <style>\n .table { \n display: table; \n width: 100%;\n }\n .table-row { \n display: table-... | Using HTML and CSS, create a page layout with two columns and a header row. | <html>
<head>
<style>
.table {
display: table;
width: 100%;
}
.table-row {
display: table-row;
}
.table-cell {
display: table-cell;
}
</style>
</head>
<body>
<div class="table">
<div class="table-row">
<div class="... | |
[
{
"role": "user",
"content": "Edit the following code in Java to include a new method “printName()”.\n\npublic class Person {\n String name;\n void displayAge(){\n System.out.println(\"age is: \"+ age); \n }\n}"
},
{
"role": "assistant",
"content": "public class Person {\n S... | Edit the following code in Java to include a new method “printName()”. | public class Person {
String name;
void displayAge(){
System.out.println("age is: "+ age);
}
} | public class Person {
String name;
void displayAge(){
System.out.println("age is: "+ age);
}
void printName(){
System.out.println("Name: "+ name);
}
} |
[
{
"role": "user",
"content": "Create a HTML page which includes two input fields and a button that generates output field that should contain the sum of the two numbers given in the two input fields."
},
{
"role": "assistant",
"content": "<!DOCTYPE html>\n<html>\n <head>\n <title>Sum Calcula... | Create a HTML page which includes two input fields and a button that generates output field that should contain the sum of the two numbers given in the two input fields. | <!DOCTYPE html>
<html>
<head>
<title>Sum Calculator</title>
<script>
function calculate() {
var num1 = Number(document.getElementById("num1").value);
var num2 = Number(document.getElementById("num2").value);
document.getElementById("output").innerHTML = num1 + num2;
}
<... | |
[
{
"role": "user",
"content": "What is the data structure of a hash table?"
},
{
"role": "assistant",
"content": "A hash table is a data structure that maps keys to values using a hash function. It is composed of a key-value pair, where the key is used to locate a specific item in the table, and ... | What is the data structure of a hash table? | A hash table is a data structure that maps keys to values using a hash function. It is composed of a key-value pair, where the key is used to locate a specific item in the table, and the value is the item itself. | |
[
{
"role": "user",
"content": "Create a program that outputs the results of an election.\n\nvotes = [(\"A\", 55), (\"B\", 43), (\"C\", 21)]"
},
{
"role": "assistant",
"content": "votes = [(\"A\", 55), (\"B\", 43), (\"C\", 21)]\n\ntotal = 0\nfor name, count in votes:\n total += count\n\nfor nam... | Create a program that outputs the results of an election. | votes = [("A", 55), ("B", 43), ("C", 21)] | votes = [("A", 55), ("B", 43), ("C", 21)]
total = 0
for name, count in votes:
total += count
for name, count in votes:
print("{}: {:.2f}%".format(name, count/total*100))
# Output:
# A: 59.77%
# B: 47.60%
# C: 23.63% |
[
{
"role": "user",
"content": "Create a Python function that prints all the values in a dictionary.\n\nDictionary: { \"a\": 1, \"b\": 2, \"c\": 3 }"
},
{
"role": "assistant",
"content": "def printDictValues(dict):\n for key, value in dict.items():\n print(value)\n\nprintDictValues({\"a... | Create a Python function that prints all the values in a dictionary. | Dictionary: { "a": 1, "b": 2, "c": 3 } | def printDictValues(dict):
for key, value in dict.items():
print(value)
printDictValues({"a": 1, "b": 2, "c": 3}) |
[
{
"role": "user",
"content": "Fill in the blank with appropriate generic function to complete the code.\n\ndef foo():\n value = ____"
},
{
"role": "assistant",
"content": "def foo():\n value = input()"
}
] | Fill in the blank with appropriate generic function to complete the code. | def foo():
value = ____ | def foo():
value = input() |
[
{
"role": "user",
"content": "Create a list of 3 objects in Python."
},
{
"role": "assistant",
"content": "list = [1, \"hello\", {'name': 'John'}]"
}
] | Create a list of 3 objects in Python. | list = [1, "hello", {'name': 'John'}] | |
[
{
"role": "user",
"content": "Write a query in SQL to list the products from a given supplier."
},
{
"role": "assistant",
"content": "SELECT * FROM Products \nWHERE SupplierId = 'SupplierId'"
}
] | Write a query in SQL to list the products from a given supplier. | SELECT * FROM Products
WHERE SupplierId = 'SupplierId' | |
[
{
"role": "user",
"content": "Imagine you have an array with the following elements: [3, 7, 2, 8, 1, 4]. Sort the array so that the elements are in ascending order."
},
{
"role": "assistant",
"content": "[1, 2, 3, 4, 7, 8]"
}
] | Imagine you have an array with the following elements: [3, 7, 2, 8, 1, 4]. Sort the array so that the elements are in ascending order. | [1, 2, 3, 4, 7, 8] | |
[
{
"role": "user",
"content": "Create an SQL query to find the id of the customer whose name is \"John Doe\"."
},
{
"role": "assistant",
"content": "SELECT id FROM customers WHERE name = 'John Doe';"
}
] | Create an SQL query to find the id of the customer whose name is "John Doe". | SELECT id FROM customers WHERE name = 'John Doe'; | |
[
{
"role": "user",
"content": "Write CSS code to position a div in the middle and bottom of the page."
},
{
"role": "assistant",
"content": "div {\n position: absolute;\n bottom: 0;\n left: 50%;\n transform: translateX(-50%);\n}"
}
] | Write CSS code to position a div in the middle and bottom of the page. | div {
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
} | |
[
{
"role": "user",
"content": "Given the following text, create a Python function that finds the number of unique words in the text.\n\nThis is a sample text to find the number of unique words."
},
{
"role": "assistant",
"content": "def find_unique_words(text):\n words = set(text.split(\" \"))... | Given the following text, create a Python function that finds the number of unique words in the text. | This is a sample text to find the number of unique words. | def find_unique_words(text):
words = set(text.split(" "))
return len(words)
unique_words = find_unique_words("This is a sample text to find the number of unique words.")
print(unique_words) |
[
{
"role": "user",
"content": "What is the C# code to check if a number is divisible by 5?"
},
{
"role": "assistant",
"content": "bool isDivisibleByFive(int number) \n{ \n return number % 5 == 0; \n}"
}
] | What is the C# code to check if a number is divisible by 5? | bool isDivisibleByFive(int number)
{
return number % 5 == 0;
} | |
[
{
"role": "user",
"content": "Design a python class for a dog to print its name and age when given.\n\nGinger, 3"
},
{
"role": "assistant",
"content": "class Dog:\n def __init__(self, name, age):\n self.name = name\n self.age = age\n\n def get_name(self):\n return self... | Design a python class for a dog to print its name and age when given. | Ginger, 3 | class Dog:
def __init__(self, name, age):
self.name = name
self.age = age
def get_name(self):
return self.name
def get_age(self):
return self.age
dog = Dog('Ginger', 3)
print(dog.get_name())
print(dog.get_age()) |
[
{
"role": "user",
"content": "Write a code snippet to print the minutes between two timestamps.\n\nt1 = datetime.datetime(2020, 1, 1, 12, 0)\nt2 = datetime.datetime(2020, 1, 1, 15, 30)"
},
{
"role": "assistant",
"content": "from datetime import datetime, timedelta\n\nt1 = datetime(2020, 1, 1, 12... | Write a code snippet to print the minutes between two timestamps. | t1 = datetime.datetime(2020, 1, 1, 12, 0)
t2 = datetime.datetime(2020, 1, 1, 15, 30) | from datetime import datetime, timedelta
t1 = datetime(2020, 1, 1, 12, 0)
t2 = datetime(2020, 1, 1, 15, 30)
minutes_difference = int((t2-t1).total_seconds()/60)
print("The difference in minutes between the two timestamps is: " + str(minutes_difference) + " minutes.") |
[
{
"role": "user",
"content": "Create a random phone number."
},
{
"role": "assistant",
"content": "(402) 904-6151"
}
] | Create a random phone number. | (402) 904-6151 | |
[
{
"role": "user",
"content": "Construct a SQL query to group students by the grade they got, and calculate the average score."
},
{
"role": "assistant",
"content": "SELECT grade, AVG(score) \nFROM students \nGROUP BY grade"
}
] | Construct a SQL query to group students by the grade they got, and calculate the average score. | SELECT grade, AVG(score)
FROM students
GROUP BY grade | |
[
{
"role": "user",
"content": "Write a Python code to initialize a 10 x 10 matrix with random values."
},
{
"role": "assistant",
"content": "import random\n\ndef init_matrix():\n matrix = [[0 for _ in range(10)] for _ in range(10)]\n for i in range(len(matrix)):\n for j in range(len(... | Write a Python code to initialize a 10 x 10 matrix with random values. | import random
def init_matrix():
matrix = [[0 for _ in range(10)] for _ in range(10)]
for i in range(len(matrix)):
for j in range(len(matrix[0])):
matrix[i][j] = random.randint(0,100)
return matrix | |
[
{
"role": "user",
"content": "Create a for-loop in Python for printing all numbers from 1 to 9 (inclusive)."
},
{
"role": "assistant",
"content": "for x in range(1, 10): \n print(x)"
}
] | Create a for-loop in Python for printing all numbers from 1 to 9 (inclusive). | for x in range(1, 10):
print(x) | |
[
{
"role": "user",
"content": "How can you access the value of a key from a JavaScript object?"
},
{
"role": "assistant",
"content": "You can access a value from a JavaScript object using either dot notation or square bracket notation. \n\nUsing dot notation, you can do something like \"object.ke... | How can you access the value of a key from a JavaScript object? | You can access a value from a JavaScript object using either dot notation or square bracket notation.
Using dot notation, you can do something like "object.key", where the key is the name of the property you want to access.
Using bracket notation, you can do something like "object["key"]", where the key is a string... | |
[
{
"role": "user",
"content": "Write a SQL query to display the name and country of the customers who have purchased products in the last 24 hours."
},
{
"role": "assistant",
"content": "SELECT name, country \nFROM customers \nWHERE orderDate > DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 DAY);"
}
] | Write a SQL query to display the name and country of the customers who have purchased products in the last 24 hours. | SELECT name, country
FROM customers
WHERE orderDate > DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 DAY); | |
[
{
"role": "user",
"content": "Generate an HTML table with 3 columns for Name, Email and Phone Number."
},
{
"role": "assistant",
"content": "<table>\n <tr>\n <th>Name</th>\n <th>Email</th>\n <th>Phone Number</th>\n </tr>\n <tr>\n <td>John Doe</td>\n <t... | Generate an HTML table with 3 columns for Name, Email and Phone Number. | <table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone Number</th>
</tr>
<tr>
<td>John Doe</td>
<td>john@example.com</td>
<td>123-456-7890</td>
</tr>
</table> | |
[
{
"role": "user",
"content": "Output a list of all even numbers between two given positive integers m and n.\n\nm=2, n=10"
},
{
"role": "assistant",
"content": "def evenNumbers(m,n):\n evenNum=[]\n for i in range(m,n+1):\n if i%2 == 0:\n evenNum.append(i)\n return even... | Output a list of all even numbers between two given positive integers m and n. | m=2, n=10 | def evenNumbers(m,n):
evenNum=[]
for i in range(m,n+1):
if i%2 == 0:
evenNum.append(i)
return evenNum |
[
{
"role": "user",
"content": "Replace the \"TODO\" comment in the given code with appropriate code.\n\nif <condition>:\n # TODO"
},
{
"role": "assistant",
"content": "if <condition>:\n print(\"Condition is satisfied\")"
}
] | Replace the "TODO" comment in the given code with appropriate code. | if <condition>:
# TODO | if <condition>:
print("Condition is satisfied") |
[
{
"role": "user",
"content": "Write a REGEX pattern to match strings consisting of three numbers separated by a dash."
},
{
"role": "assistant",
"content": "^\\d{1,3}-\\d{1,3}-\\d{1,3}$"
}
] | Write a REGEX pattern to match strings consisting of three numbers separated by a dash. | ^\d{1,3}-\d{1,3}-\d{1,3}$ | |
[
{
"role": "user",
"content": "Write a snippet of code for looping over a list of numbers.\n\nmyList = [1, 2, 3, 4]"
},
{
"role": "assistant",
"content": "for x in myList:\n print(x)"
}
] | Write a snippet of code for looping over a list of numbers. | myList = [1, 2, 3, 4] | for x in myList:
print(x) |
[
{
"role": "user",
"content": "Modify the following code segment to add multiple values in an array\n\nvar myArray = [];\nmyArray[0] = 'x';"
},
{
"role": "assistant",
"content": "var myArray = [];\nmyArray.push('x', 'y', 'z');"
}
] | Modify the following code segment to add multiple values in an array | var myArray = [];
myArray[0] = 'x'; | var myArray = [];
myArray.push('x', 'y', 'z'); |
[
{
"role": "user",
"content": "Generate a URL in JavaScript for an API endpoint to fetch data from a given database table.\n\nTable Name: users"
},
{
"role": "assistant",
"content": "const generateURL = (tableName) => {\n return `https://website.com/api/v1/table/${tableName}`;\n}\n\nconst url = ... | Generate a URL in JavaScript for an API endpoint to fetch data from a given database table. | Table Name: users | const generateURL = (tableName) => {
return `https://website.com/api/v1/table/${tableName}`;
}
const url = generateURL('users');
// Output: https://website.com/api/v1/table/users |
[
{
"role": "user",
"content": "Suppose you are given a array of 0s,1s and 2s . Write a program to sort the given input array."
},
{
"role": "assistant",
"content": "def sortArray(arr): \n \n # loop to run for every element in the array \n for i in range(len(arr)): \n \n ... | Suppose you are given a array of 0s,1s and 2s . Write a program to sort the given input array. | def sortArray(arr):
# loop to run for every element in the array
for i in range(len(arr)):
# loop to run for elements till the sorted part
for j in range(0, len(arr)-i-1):
# If a element is found to be greater than its next element then swap them
... | |
[
{
"role": "user",
"content": "Convert the following statement into valid Python syntax.\n\nx = \"string\""
},
{
"role": "assistant",
"content": "x = 'string'"
}
] | Convert the following statement into valid Python syntax. | x = "string" | x = 'string' |
[
{
"role": "user",
"content": "Parse and convert a string containing a valid JSON to a Python dictionary.\n\nstring = '{ \"a\": 1, \"b\": 2, \"c\": 3 }'"
},
{
"role": "assistant",
"content": "import json\n\ndef convert_json_string(string):\n return json.loads(string)\n\nconvert_json_string(str... | Parse and convert a string containing a valid JSON to a Python dictionary. | string = '{ "a": 1, "b": 2, "c": 3 }' | import json
def convert_json_string(string):
return json.loads(string)
convert_json_string(string) # Returns { "a": 1, "b": 2, "c": 3 } |
[
{
"role": "user",
"content": "Write a Python program to convert a string to a list. The string is \"This is a test\".\n\n\"This is a test\""
},
{
"role": "assistant",
"content": "\"\"\"\nWrite a Python program to convert a string to a list.\n\"\"\"\ndef string_to_list(str):\n return str.split... | Write a Python program to convert a string to a list. The string is "This is a test". | "This is a test" | """
Write a Python program to convert a string to a list.
"""
def string_to_list(str):
return str.split()
if __name__ == '__main__':
str = "This is a test"
print(string_to_list(str)) |
[
{
"role": "user",
"content": "Create a C# class with an interface that can be used to store and manipulate data."
},
{
"role": "assistant",
"content": "public class DataManipulator\n{\n public interface IDataManipulator\n {\n void StoreData(string data);\n void ManipulateData... | Create a C# class with an interface that can be used to store and manipulate data. | public class DataManipulator
{
public interface IDataManipulator
{
void StoreData(string data);
void ManipulateData();
}
} | |
[
{
"role": "user",
"content": "Create an iOS table view to display the list of items."
},
{
"role": "assistant",
"content": "class TableViewController: UITableViewController {\n\n override func viewDidLoad() {\n super.viewDidLoad()\n tableView.dataSource = self\n }\n \n ... | Create an iOS table view to display the list of items. | class TableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
}
override func numberOfSections(in tableView: UITableView) -> Int {
// Number of sections your table view has
return 1
}
overri... | |
[
{
"role": "user",
"content": "Design a Java class for a Car which has the following attributes: name, model, year, and price."
},
{
"role": "assistant",
"content": "class Car {\n \n private String name;\n private String model; \n private int year;\n private double price;\n \n //constructor to in... | Design a Java class for a Car which has the following attributes: name, model, year, and price. | class Car {
private String name;
private String model;
private int year;
private double price;
//constructor to initialize Car object
public Car(String name, String model, int year, double price) {
this.name = name;
this.model = model;
this.year = year;
this.price = price;
}
//getters and setters... | |
[
{
"role": "user",
"content": "Create a method that returns all elements in an array that are larger than the given value x.\n\n[2, 3, 5, 7, 11, 13] and x = 4"
},
{
"role": "assistant",
"content": "def elements_greater_than_x(arr, x):\n result = []\n\n for el in arr:\n if el > x:\n resu... | Create a method that returns all elements in an array that are larger than the given value x. | [2, 3, 5, 7, 11, 13] and x = 4 | def elements_greater_than_x(arr, x):
result = []
for el in arr:
if el > x:
result.append(el)
return result |
[
{
"role": "user",
"content": "Create a Java class for car objects."
},
{
"role": "assistant",
"content": "public class Car {\n\n private String make;\n private String model;\n private int year;\n\n public Car(String make, String model, int year) {\n this.make = make;\n ... | Create a Java class for car objects. | public class Car {
private String make;
private String model;
private int year;
public Car(String make, String model, int year) {
this.make = make;
this.model = model;
this.year = year;
}
public String getMake() {
return make;
}
public String getModel(... | |
[
{
"role": "user",
"content": "Implement a function that takes two integers and returns the smaller one."
},
{
"role": "assistant",
"content": "def min_integer(a, b):\n \"\"\"This function returns the minimum of two integers\"\"\"\n return min(a, b)"
}
] | Implement a function that takes two integers and returns the smaller one. | def min_integer(a, b):
"""This function returns the minimum of two integers"""
return min(a, b) | |
[
{
"role": "user",
"content": "Create a class that represents a circle\n\nradius = 5.5"
},
{
"role": "assistant",
"content": "class Circle:\n def __init__(self, radius):\n self.radius = radius\n def area(self):\n return self.radius * self.radius * 3.14\n\nc = Circle(radius) \n... | Create a class that represents a circle | radius = 5.5 | class Circle:
def __init__(self, radius):
self.radius = radius
def area(self):
return self.radius * self.radius * 3.14
c = Circle(radius)
print(c.area()) # Output: 95.033 |
[
{
"role": "user",
"content": "Generate a string of 5 random characters from the characters A through Z."
},
{
"role": "assistant",
"content": "import random\n\ndef random_string():\n chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'\n random_string = ''.join(random.choice(chars) for i in range(5))\n ... | Generate a string of 5 random characters from the characters A through Z. | import random
def random_string():
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
random_string = ''.join(random.choice(chars) for i in range(5))
return random_string
print(random_string()) | |
[
{
"role": "user",
"content": "Retrieve the third item from a linked list."
},
{
"role": "assistant",
"content": "def get_third_item(linked_list):\n curr_node = linked_list\n for i in range(2):\n curr_node = curr_node.next # Moves onto the third item. \n return curr_node.data # Re... | Retrieve the third item from a linked list. | def get_third_item(linked_list):
curr_node = linked_list
for i in range(2):
curr_node = curr_node.next # Moves onto the third item.
return curr_node.data # Returns the data of the third item. | |
[
{
"role": "user",
"content": "Create a class called \"Computer\" with two attributes \"name\" and \"model\" and two methods \"get_name\" and \"get_model\"."
},
{
"role": "assistant",
"content": "class Computer:\n def __init__(self, name, model):\n self.name = name\n self.model =... | Create a class called "Computer" with two attributes "name" and "model" and two methods "get_name" and "get_model". | class Computer:
def __init__(self, name, model):
self.name = name
self.model = model
def get_name(self):
return self.name
def get_model(self):
return self.model | |
[
{
"role": "user",
"content": "Write an Objective-C program for printing the factorial of a number 5.\n\nInteger number: 5"
},
{
"role": "assistant",
"content": "#include <stdio.h>\n\nint factorial(int n)\n{\n int result = 1;\n for (int i = 1; i <= n; i++) {\n result *= i;\n }\n ... | Write an Objective-C program for printing the factorial of a number 5. | Integer number: 5 | #include <stdio.h>
int factorial(int n)
{
int result = 1;
for (int i = 1; i <= n; i++) {
result *= i;
}
return result;
}
int main()
{
int input = 5;
int result = factorial(input);
printf("The factorial of %d is %d", input, result);
return 0;
} |
[
{
"role": "user",
"content": "Create a PHP script that can validate if a given string is a valid IP address."
},
{
"role": "assistant",
"content": "function validateIP(ip) { \n return filter_var(ip, FILTER_VALIDATE_IP); \n}"
}
] | Create a PHP script that can validate if a given string is a valid IP address. | function validateIP(ip) {
return filter_var(ip, FILTER_VALIDATE_IP);
} | |
[
{
"role": "user",
"content": "Create a CSS class that aligns its content left."
},
{
"role": "assistant",
"content": ".left-align {\n text-align: left;\n}"
}
] | Create a CSS class that aligns its content left. | .left-align {
text-align: left;
} | |
[
{
"role": "user",
"content": "Create an HTML page that renders two checkboxes and a button using JavaScript."
},
{
"role": "assistant",
"content": "<html>\n <head>\n <script>\n function renderCheckboxes() {\n var checkboxes = document.createElement(\"input\");... | Create an HTML page that renders two checkboxes and a button using JavaScript. | <html>
<head>
<script>
function renderCheckboxes() {
var checkboxes = document.createElement("input");
checkboxes.type = "checkbox";
checkboxes.name = "checkbox";
checkboxes.value = "1";
document.body.app... | |
[
{
"role": "user",
"content": "How does the fadeIn() function work in jQuery?"
},
{
"role": "assistant",
"content": "The fadeIn() function in jQuery is used to gradually increase the opacity of an element from hidden to visible, in a specified duration. The function works by adjusting the CSS pro... | How does the fadeIn() function work in jQuery? | The fadeIn() function in jQuery is used to gradually increase the opacity of an element from hidden to visible, in a specified duration. The function works by adjusting the CSS property for opacity for the element, from 0 to 1, over a specified duration of time. | |
[
{
"role": "user",
"content": "Create an if-elseif-else statement in JavaScript"
},
{
"role": "assistant",
"content": "if (condition1) {\n // code to execute if condition1 is true\n} else if (condition2) {\n // code to execute if condition2 is true\n} else {\n // code to execute if both ... | Create an if-elseif-else statement in JavaScript | if (condition1) {
// code to execute if condition1 is true
} else if (condition2) {
// code to execute if condition2 is true
} else {
// code to execute if both condition1 and condition2 are false
} | |
[
{
"role": "user",
"content": "Create a function to remove all duplicated words from an input sentence.\n\nsentence = \"Hello World Bye World\""
},
{
"role": "assistant",
"content": "def remove_duplicates_from_sentence(sentence): \n split_words = sentence.split(' ')\n no_duplicates = list(s... | Create a function to remove all duplicated words from an input sentence. | sentence = "Hello World Bye World" | def remove_duplicates_from_sentence(sentence):
split_words = sentence.split(' ')
no_duplicates = list(set(split_words))
return ' '.join(no_duplicates) |
[
{
"role": "user",
"content": "Write a code to parse the following JSON into a dictionary\n\n{\n \"firstName\": \"John\",\n \"lastName\": \"Smith\",\n \"age\": 25\n}"
},
{
"role": "assistant",
"content": "import json \n\ndef parse_json(json_data):\n data = json.loads(json_data)\n return ... | Write a code to parse the following JSON into a dictionary | {
"firstName": "John",
"lastName": "Smith",
"age": 25
} | import json
def parse_json(json_data):
data = json.loads(json_data)
return {key: data[key] for key in data} |
[
{
"role": "user",
"content": "Name the most important benefit of using a database system."
},
{
"role": "assistant",
"content": "The most important benefit of using a database system is the ability to store and retrieve data quickly and easily. Database systems also provide support for data secu... | Name the most important benefit of using a database system. | The most important benefit of using a database system is the ability to store and retrieve data quickly and easily. Database systems also provide support for data security, data integrity, and concurrently accessing and modifying data from multiple systems. | |
[
{
"role": "user",
"content": "Write a regular expression to match all valid UK postcodes."
},
{
"role": "assistant",
"content": "^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z]))))[0-9][A-Za-z]{2})... | Write a regular expression to match all valid UK postcodes. | ^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z]))))[0-9][A-Za-z]{2})$ | |
[
{
"role": "user",
"content": "Write a PHP program to build a dynamic HTML table with the details of 10 students."
},
{
"role": "assistant",
"content": "$students = [\n [\n 'name' => 'John Doe',\n 'age' => 22,\n 'marks' => 91\n ],\n [\n 'name' => 'Jane Doe',\n... | Write a PHP program to build a dynamic HTML table with the details of 10 students. | $students = [
[
'name' => 'John Doe',
'age' => 22,
'marks' => 91
],
[
'name' => 'Jane Doe',
'age' => 21,
'marks' => 87
],
// ...
];
$html = "<table>
<tr>
<th>Name</th>
<th>Age</th>
<th>Marks</th>
</tr>";
foreach ($stud... | |
[
{
"role": "user",
"content": "Create a SQL query to find the total revenue for services in the month of February."
},
{
"role": "assistant",
"content": "SELECT SUM(t.total)\nFROM orders o\nINNER JOIN order_items t ON o.order_id = t.order_id\nINNER JOIN products p ON t.product_id = p.product_id\n... | Create a SQL query to find the total revenue for services in the month of February. | SELECT SUM(t.total)
FROM orders o
INNER JOIN order_items t ON o.order_id = t.order_id
INNER JOIN products p ON t.product_id = p.product_id
WHERE p.type = 'service'
AND MONTH(o.order_date) = 2
AND YEAR(o.order_date) = YEAR(CURDATE()); | |
[
{
"role": "user",
"content": "Using a while loop, write a program to print the Fibonacci sequence."
},
{
"role": "assistant",
"content": "# function to print Fibonacci sequence \ndef fibo(n): \n counter = 0\n a = 0\n b = 1\n \n while counter < n:\n print(a, end = \" \")\n... | Using a while loop, write a program to print the Fibonacci sequence. | # function to print Fibonacci sequence
def fibo(n):
counter = 0
a = 0
b = 1
while counter < n:
print(a, end = " ")
fibonacci = a + b
a = b
b = fibonacci
counter += 1
fibo(10)
Output: 0 1 1 2 3 5 8 13 21 34 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.