Dataset Viewer
Auto-converted to Parquet Duplicate
id
string
conversations
list
5d051f34d87013e630993ed98957e2b3
[ { "role": "user", "content": "Create an array of length 5 which contains all even numbers between 1 and 10." }, { "role": "assistant", "content": "arr = [2, 4, 6, 8, 10]" } ]
59e5c19d74f6c90ce60408e176ad750e
[ { "role": "user", "content": "Formulate an equation to calculate the height of a triangle given the angle, side lengths and opposite side length." }, { "role": "assistant", "content": "Height of triangle = opposite side length * sin (angle) / side length" } ]
9e7738ac16dc0839ac15574a4920de95
[ { "role": "user", "content": "Write a replace method for a string class which replaces the given string with a given set of characters.\nstring = \"Hello World!\"\nreplace_with = \"Greetings!\"" }, { "role": "assistant", "content": "def replace(self, replace_with):\n new_string = \"\"\n fo...
d43b11e39d84c327983fabcbe16df317
[ { "role": "user", "content": "Create an array of length 15 containing numbers divisible by 3 up to 45." }, { "role": "assistant", "content": "arr = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45]" } ]
2b3969f31e5191982966eb1cf3dba1d0
[ { "role": "user", "content": "Write a function to find the number of distinct states in a given matrix.\nmatrix = [[1, 0, 0],\n [1, 0, 1],\n [1, 1, 1]]" }, { "role": "assistant", "content": "def find_num_distinct_states(matrix):\n states = set()\n for row in matrix:\n ...
9427efe5ae4a6c43ad25979400d7b050
[ { "role": "user", "content": "Create a nested loop to print every combination of numbers between 0-9" }, { "role": "assistant", "content": "for i in range(10):\n for j in range(10):\n print(i, j)" } ]
eab29291d227ddc89800cb70afee4fe5
[ { "role": "user", "content": "Write a function to find the maximum difference between two numbers in a given array.\narr = [5, 3, 17, 11, 9]" }, { "role": "assistant", "content": "def max_difference(arr):\n max_diff = 0\n for i in range(len(arr)-1):\n diff = arr[i+1] - arr[i]\n ...
0eb95f6e6db35c623b5629db02d2c904
[ { "role": "user", "content": "Write a function to generate the nth Fibonacci number.\n< noinput >" }, { "role": "assistant", "content": "def fib(n):\n if n == 0:\n return 0\n elif n == 1:\n return 1\n else:\n return fib(n-2) + fib(n-1)" } ]
ffbec09ecb18ad944313dedcb20d7825
[ { "role": "user", "content": "Write a class to represent a 2D point with x and y coordinates." }, { "role": "assistant", "content": "class Point:\n def __init__(self, x, y):\n self.x = x \n self.y = y \n \n def __str__(self): \n return \"({0},{1})\".format(self.x, se...
1ca0854e254d489edcc0510dff13bf57
[ { "role": "user", "content": "Write code that removes spaces from a given string.\nstring = \" A B C D \"" }, { "role": "assistant", "content": "def remove_spaces(string): \n return \"\".join(string.split())" } ]
e7bcc10cd311a85c97e78bfb94999038
[ { "role": "user", "content": "Write a function that checks if a give number is even or odd." }, { "role": "assistant", "content": "def is_even(n):\n if n%2 == 0:\n return True \n else:\n return False" } ]
d2adb9ecf170194bf1f7d55a0c50b229
[ { "role": "user", "content": "Write code to create a list of all prime numbers between 2 and 100." }, { "role": "assistant", "content": "def find_primes(n): \n prime_list = [2] \n for number in range(2, n + 1): \n is_prime = True\n for k in range(2, number): \n if ...
924b4f5d3a6d8786d5fd81c225e6a148
[ { "role": "user", "content": "Edit the following code to print out all even numbers from 1 to 10.\nfor i in range(1,11):\n print(i)" }, { "role": "assistant", "content": "for i in range(1,11):\n if i % 2 == 0:\n print(i)" } ]
b0e15449e8e6e190f8215b1c8a2ed393
[ { "role": "user", "content": "Write code to find the sum of all numbers between 1 and 10." }, { "role": "assistant", "content": "sum = 0\nfor i in range(1,11):\n sum += i\nprint(sum)" } ]
e33fd00b37dbd729db0c57114496896f
[ { "role": "user", "content": "Create a function to calculate the area of a given circle." }, { "role": "assistant", "content": "def area_circle(radius):\n return 3.14 * (radius**2)" } ]
d454f22e310b1f402d75ecaa1dfbf929
[ { "role": "user", "content": "Follow the comments in the code to complete the program which prints a conversion table from Fahrenheit to Celsius.\n# This program prints a conversion table from Fahrenheit to Celsius\n\n# Print a heading for the table\n# TODO\n\n# Print the column headings\n# TODO\n\n# Calcul...
c257253e76fa2248d7532b7346a896fe
[ { "role": "user", "content": "Develop a classification algorithm in Python to predict whether a bird is a hawk or a falcon." }, { "role": "assistant", "content": "import pandas as pd\nimport numpy as np\n\n# Define features\nfeatures = [\"wing_shape\", \"size\", \"tails_length\", \"color_pattern...
c26bdc8af1c80ef294a3e03eae3bcfd7
[ { "role": "user", "content": "Create a function in Java for computing the factorial of a positive integer number." }, { "role": "assistant", "content": "public static long factorial(int n) {\n if (n == 0) {\n return 1;\n }\n long result = 1;\n for (int i = 1; i <= n; i++) {\n ...
30877feb538f51a512269c4a458b9a0d
[ { "role": "user", "content": "Create a C++ program for randomly shuffling an array of integers." }, { "role": "assistant", "content": "#include <iostream>\n#include <algorithm>\n#include <random>\n\nvoid shuffleArray(int array[], int size) {\n\tstd::random_device rd;\n\tstd::mt19937 g(rd()); \n\...
f5c9160ac7040c942fbb452f4f87c96d
[ { "role": "user", "content": "Use the function to debug the given program and prevent the segmentation fault.\n#include <stdio.h>\n\nint main() {\n int array[] = {1, 2, 3, 4, 5};\n int n = 5;\n int i;\n // TODO\n for (i = 0; i <= n; i++) {\n printf(\"%d\\n\", array[i]);\n }\n ret...
0b4a3300e5a826a612462a500c22b126
[ { "role": "user", "content": "Replace the placeholder with a for loop for iterating over the numbers from 1 to n and printing them.\nfor i in range(n):\n # TODO" }, { "role": "assistant", "content": "for i in range(1, n+1):\n print(i)" } ]
b1f56e4478b68a0134c299a55b650c4e
[ { "role": "user", "content": "Use try-except statements to detect and handle exceptions in the code.\nfor i in range(n):\n x = 1/i" }, { "role": "assistant", "content": "try:\n for i in range(n):\n x = 1/i\nexcept ZeroDivisionError:\n print(\"Zero division error encountered!\")" ...
838a43d6680be0b584bb3eebbf150b3d
[ { "role": "user", "content": "Re-write the code segment as a list comprehension.\nnumbers = []\nfor i in range(10):\n if i % 2 == 0:\n numbers.append(i)" }, { "role": "assistant", "content": "numbers = [i for i in range(10) if i % 2 == 0]" } ]
6cedae38b75440eb340dc595686bc8dd
[ { "role": "user", "content": "Remove the boilerplate code from the program for printing 10 random numbers.\nimport random\n\n# Generate 10 random numbers\nfor i in range(10):\n # TODO" }, { "role": "assistant", "content": "import random\n\n# Generate 10 random numbers\nfor i in range(10):\n ...
eadf20c8ccf69ef447e42feac1d66759
[ { "role": "user", "content": "Modify the code to perform the mathematical expression “x to the power of y”.\n# Calculate x to the power of y\n# TODO" }, { "role": "assistant", "content": "# Calculate x to the power of y\nx_pow_y = x**y" } ]
7665a49f71f64677de472eefd87b77c3
[ { "role": "user", "content": "Create a dictionary for counting the occurrence of each letter in the given string.\nstring = \"hello world\"\n#TODO" }, { "role": "assistant", "content": "string = \"hello world\"\nletter_counts = {}\n\nfor letter in string:\n if letter in letter_counts:\n ...
ccfcd3c9ed2cabb665ad0bec4eaf1c8e
[ { "role": "user", "content": "Follow the comments to complete the code that finds the maximum value in an array.\n# Find the maximum value in an array\narr = [4, 5, 2, 8, 7]\n# TODO" }, { "role": "assistant", "content": "# Find the maximum value in an array\narr = [4, 5, 2, 8, 7]\n\nmax_value = ...
21182af88b9fe5cddcc26442185c924d
[ { "role": "user", "content": "Write a function in HTML for creating a table of n rows and m columns." }, { "role": "assistant", "content": "<table>\n <tbody>\n <% for (let i = 0; i < n; i++) { %>\n <tr>\n <% for (let j = 0; j < m; j++) { %>\n <td>Cell Content</td>\n ...
e0035e1bf9fc052ccdba4c1a3959a0db
[ { "role": "user", "content": "Create a CSS script that centers the login form on the webpage." }, { "role": "assistant", "content": ".login-form {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n}" } ]
d190a7be015a513198a8d332e5492ca5
[ { "role": "user", "content": "Create a Java program that prints out the sum of the numbers in the array.\nint[] numbers = {1, 2, 3 , 4, 5};" }, { "role": "assistant", "content": "public class SumOfArray {\n public static void main(String[] args) {\n int[] numbers = {1, 2, 3 , 4, 5};\n ...
417d295a43b9d858479439ee378986bc
[ { "role": "user", "content": "Write a SQL query to calculate the total number of orders in the \"orders\" table." }, { "role": "assistant", "content": "SELECT COUNT(*) AS \"Total Number of Orders\" \nFROM orders;" } ]
75d41d9d5ff07c23ec254df1eea78d3a
[ { "role": "user", "content": "Write a Python function to convert a given string to lowercase.\nstring = \"FOO\"" }, { "role": "assistant", "content": "def to_lowercase(string):\n return string.lower()\n\nstring = \"FOO\"\nprint(to_lowercase(string))" } ]
04f94bf12cbf905829b1952bc66b34af
[ { "role": "user", "content": "Create a C program that prints out the Fibonacci sequence." }, { "role": "assistant", "content": "#include <stdio.h>\n\nint main()\n{\n int i, num, first=0, second=1, next;\n printf(\"Enter the number of elements: \");\n scanf(\"%d\", &num);\n printf(\"F...
d8178d099dbfa5caa9e82d6825f059e9
[ { "role": "user", "content": "Write a function in JavaScript to count the number of vowels in a given string.\nconst string = \"abcdefg\"" }, { "role": "assistant", "content": "function countVowels(string) {\n let vowelCount = 0;\n const vowels = [\"a\",\"e\",\"i\",\"o\",\"u\"];\n \n f...
25fda2ab8cd1e95e5a92fe0d96adaf94
[ { "role": "user", "content": "Create a JSX code that renders a \"Hello, World!\" message in the browser." }, { "role": "assistant", "content": "import React from \"react\";\n\nfunction App() {\n return (\n <div>\n <h1>Hello, World!</h1>\n </div>\n );\n}\n\nexport default App;" } ]
e13f412874d106b60de551aba01f2d90
[ { "role": "user", "content": "Write an SQL query to calculate the average order price for each product category in the \"orders\" table." }, { "role": "assistant", "content": "SELECT category, AVG(price) as \"Average Order Price\"\nFROM orders\nGROUP BY category;" } ]
6a8e99dca21ce8da55808652bd00f067
[ { "role": "user", "content": "Create a Java program that prints out the contents of a given two-dimensional array.\nint[][] arr = {{1,2},{3,4},{5,6}}" }, { "role": "assistant", "content": "public class TwoDArray {\n\n public static void main(String[] args) {\n int[][] arr = {{1,2},{3,4...
cb77949e91faf8d5b08886568f903071
[ { "role": "user", "content": "Create a C++ program that sorts a given array in descending order.\nint array[] = {6, 3, 8, 12, 9, 4};" }, { "role": "assistant", "content": "#include<iostream>\nusing namespace std;\n \nint main()\n{\n int array[] = {6, 3, 8, 12, 9, 4};\n int arraySize = size...
e1b480559286bbc9b1d4a598fb135851
[ { "role": "user", "content": "Edit the Python code so that it prints out the total number of elements in the list.\nlist = [1, 2, 3, 4, 5]" }, { "role": "assistant", "content": "list = [1, 2, 3, 4, 5]\nprint(\"Total number of elements in the list: \", len(list))" } ]
84a6d6b856372b15ecd9f938bd35358c
[ { "role": "user", "content": "Create a Swift code that show the number of days in the given month.\nint month = 5" }, { "role": "assistant", "content": "let month = 5\nlet daysEndingInth = [3, 0, 3, 2, 3, 2, 3, 3, 2, 3, 2, 3]\nlet daysInMonth = daysEndingInth[month - 1] \nprint(\"The number of d...
30997de34a582a77f6298c5af0df534d
[ { "role": "user", "content": "Write a HTML code that create a form for user to fill out their current address." }, { "role": "assistant", "content": "<form action=\"\">\n <label for=\"street\">Street</label>\n <input type=\"text\" name=\"street\" id=\"street\">\n <label for=\"city\">Cit...
8dfcebfda52f6cd1448f80725eb5a805
[ { "role": "user", "content": "Write a SQL query to find the total number of orders placed between two given dates.\nstart_date = '2020-01-01'\nend_date = '2020-02-01'" }, { "role": "assistant", "content": "SELECT COUNT(*)\nFROM orders\nWHERE order_date BETWEEN '2020-01-01' AND '2020-02-01';" }...
eb7edb7c034f8995d2147db76389c7a4
[ { "role": "user", "content": "Create a Ruby code that prints out the median of a given array of numbers.\nnums = [1, 7, 3, 6]" }, { "role": "assistant", "content": "nums = [1, 7, 3, 6]\nsorted_nums = nums.sort\n\n# Calculation of median \nif sorted_nums.length % 2 == 0\n mid_index = sorted_nums...
6b40ae0039ed060f4bb0fd726dbbf088
[ { "role": "user", "content": "Create a PHP code to check if an array contains a given item.\n$input_array = array(1,2,3,4,5);\n$item_to_check = 3;" }, { "role": "assistant", "content": "<?php\n$input_array = array(1,2,3,4,5);\n$item_to_check = 3;\n\nif(in_array($item_to_check, $input_array)) {\n...
db5b323f13d22c9bc2218e3f3cb4716f
[ { "role": "user", "content": "Edit the code to create a try-except block to handle the exception.\na = 5\nb = 0\n\nans = a/b" }, { "role": "assistant", "content": "try:\n a = 5\n b = 0\n\n ans = a/b\nexcept ZeroDivisionError:\n print(\"Cannot divide by zero.\")" } ]
165b89b43473d491d5000dd3a5cab7c5
[ { "role": "user", "content": "Write a script using Bash that replaces all vowels with a number." }, { "role": "assistant", "content": "#!/bin/bash\n\nstring=\"Hello World!\"\nvowels=(\"a\" \"e\" \"i\" \"o\" \"u\" \"A\" \"E\" \"I\" \"O\" \"U\")\n\nfor i in \"${vowels[@]}\"\ndo\n string=\"${str...
065253d4aa107dc339edb06c24f92f7c
[ { "role": "user", "content": "Change the variable `x` to the data type desired.\nx = 'Hello World!'" }, { "role": "assistant", "content": "x = \"Hello World!\"" } ]
5392a0c49ac49974c2ca550264db5eb9
[ { "role": "user", "content": "Create a function that takes an array as an argument and returns the sum of all the elements in the array.\narr = [1, 2, 3, 4, 5]" }, { "role": "assistant", "content": "def arraySum(arr):\n total = 0\n for num in arr:\n total += num\n return total" ...
1bace99b3c13ddf35fdaf7eddc5045e3
[ { "role": "user", "content": "Sort the array in ascending order.\narr = [3, 2, 1, 5, 4]" }, { "role": "assistant", "content": "arr.sort() # [1, 2, 3, 4, 5]" } ]
5332378e91ee676bc2bce6f5de372084
[ { "role": "user", "content": "Generate a random integer between 4 and 8 (inclusively)." }, { "role": "assistant", "content": "import random\nx = random.randint(4, 8)" } ]
5970d9fb4a11b895670a8f61908c10dd
[ { "role": "user", "content": "Write a list comprehension to square each number in the list.\narr = [1, 2, 3, 4, 5]" }, { "role": "assistant", "content": "arr = [x**2 for x in arr] # [1, 4, 9, 16, 25]" } ]
9d59ca2ec3d98aafcd450527a8dfee59
[ { "role": "user", "content": "Write a function that takes a string and reverses the words.\ntext = \"Hello World!\"" }, { "role": "assistant", "content": "def reverseWords(text):\n return ' '.join(text.split()[::-1])\n\nreverseWords(text) # \"World! Hello\"" } ]
77342d76a500b530a5c77db4ef4949ea
[ { "role": "user", "content": "Write a SQL query to return the sum of all salaries." }, { "role": "assistant", "content": "SELECT SUM(salary)\nFROM employees;" } ]
7ba3f259d9f5de28a5c090aa0bad1c9c
[ { "role": "user", "content": "Create a function that takes in two numbers as arguments and returns the product of the two." }, { "role": "assistant", "content": "def multiply(x, y):\n return x*y" } ]
eca2101cbe398ced0f1b36fb1560fea8
[ { "role": "user", "content": "Sum up the numbers in the array in Javascript.\narr = [1,2,3,4,5]" }, { "role": "assistant", "content": "let sum = arr.reduce((total, num) => total + num);\nconsole.log(sum); // 15" } ]
f0f99eb02e032cd6c42af6615ce57d3c
[ { "role": "user", "content": "Using the given function, create a loop that counts from 0 to 9.\nfunction printNum(num){\n console.log(num)\n}" }, { "role": "assistant", "content": "for (let i = 0; i < 10; i++){\n printNum(i);\n}" } ]
a7591a08e12f65659ee1e2ac751a5f2a
[ { "role": "user", "content": "Create a JSON object with three key-value pairs." }, { "role": "assistant", "content": "{\n \"firstName\": \"John\",\n \"lastName\": \"Doe\",\n \"age\": 30\n}" } ]
7c82b7cc4f1714f64b1638cd43942826
[ { "role": "user", "content": "Count the number of characters in the string.\ntext = \"Hello World!\"" }, { "role": "assistant", "content": "len(text) # 12" } ]
25a0d5ddada4eb28c28cf3fd075beddf
[ { "role": "user", "content": "Generate a random number between 0 and 1 (inclusively)." }, { "role": "assistant", "content": "Math.random(); // a random number between 0 and 1 (inclusively)" } ]
3bb341539dcb30c657b0273d25774cb3
[ { "role": "user", "content": "Compose a function named average_list which takes a list of numbers as its argument and computes the average." }, { "role": "assistant", "content": "def average_list(nums):\n return sum(nums)/len(nums)" } ]
45b7b8cde5695f253df5dd4c7285d55f
[ { "role": "user", "content": "Generate a snippet of code to extract all the URLs from the given string.\nThis string contains some urls such as https://www.google.com and https://www.facebook.com." }, { "role": "assistant", "content": "import re\n\nstring = \"This string contains some urls such ...
de7d3393df7a4f2dc48d3aeddf3ceacf
[ { "role": "user", "content": "Write a code to convert a given spredsheet in csv format to json format." }, { "role": "assistant", "content": "import csv\nimport json\n\ndef csv_to_json():\n # Path of csv file\n file_csv = 'mycsvfile.csv'\n \n # Path of json file\n file_json = 'myj...
d852e8d6d156999744a42c3eebb2b512
[ { "role": "user", "content": "Create a list comprehension to generate a list of multiples of 3 from 0 to 23." }, { "role": "assistant", "content": "list_of_multiples_of_3 = [x*3 for x in range(8)]" } ]
3497c0121821977eb8a28dfaeca0f47d
[ { "role": "user", "content": "Design a program to find the longest element in the given list.\n[10, 100, 200, 500, 400]" }, { "role": "assistant", "content": "def longest_element(list):\n max_length = 0\n max_length_item = None\n\n for item in list:\n if len(item) > max_length:\n max_...
2e19be5f3353e92fc464b1468d93f3d0
[ { "role": "user", "content": "Write a function to print all prime numbers between two given numbers." }, { "role": "assistant", "content": "def print_prime_numbers_in_range(start, end):\n # start = starting number\n # end = ending number\n\n for num in range(start, end+1):\n # Prime number...
58bc26c6e225bcedf4075b75daf42acc
[ { "role": "user", "content": "Describe the basic syntax of a Java function?" }, { "role": "assistant", "content": "A Java function consists of a function name, return type, parameters (arguments), and body. The syntax of a Java function is as follows: \npublic <return type> <function name>(<list...
4cdf3a9a723a3961df553cecbbf824e2
[ { "role": "user", "content": "How to reverse a list in C++?" }, { "role": "assistant", "content": "You can reverse a list in C++ using the std::reverse algorithm. To reverse the list, pass the list as the first parameter and the beginning and end of the list as the second and third parameter, re...
bf37c8078f06c657c8a731e2e69d943a
[ { "role": "user", "content": "Write a SQL query to update a value x in a column y in a table z.\nx = 5, y = 'amount' and z = 'payments'." }, { "role": "assistant", "content": "UPDATE payments \nSET amount = 5 \nWHERE payments.amount IS NOT NULL;" } ]
f793413890a623a360eaf0540637f5dd
[ { "role": "user", "content": "Write an algorithm in Python to determine if a number is even or odd." }, { "role": "assistant", "content": "def is_even(num): \n if num % 2 == 0: \n return True \n else: \n return False" } ]
ddd2e60a0d810f71b95ec300b7b6bccf
[ { "role": "user", "content": "What is the purpose of a constructor in a class in Java?" }, { "role": "assistant", "content": "The purpose of a constructor in a class in Java is to initialize an object of that class. A constructor is a special kind of method that is used to create an object of it...
11f09d6bd561498e5e0e2d5c87475eea
[ { "role": "user", "content": "Write a JavaScript code to get the current browser URL." }, { "role": "assistant", "content": "var currentURL = window.location.href;\nconsole.log(currentURL);" } ]
3c081477ff36b3cc545c24f610d16195
[ { "role": "user", "content": "Rewrite the following C++ code using only pointer references instead of array subscripts:\nint arr[3] = {1,2,3};\nint sum = 0;\nfor (int i = 0; i < 3; i++) \n{\n sum += arr[i];\n}" }, { "role": "assistant", "content": "int arr[3] = {1,2,3};\nint sum = 0;\nint* pt...
d323893b9bd378f5b4f0444eb176b698
[ { "role": "user", "content": "Write a MySQL query to print the column names of a table named 'employees'." }, { "role": "assistant", "content": "SELECT column_name FROM information_schema.columns WHERE table_name = 'employees';" } ]
dcdcb9b619cf48656916861c280b8194
[ { "role": "user", "content": "Generate a regular expression to match a valid email address." }, { "role": "assistant", "content": "/^([a-zA-Z0-9_\\-\\.]+)@([a-zA-Z0-9_\\-\\.]+)\\.([a-zA-Z]{2,5})$/" } ]
2d786fa605b77b034c73978a8b87de71
[ { "role": "user", "content": "How to delete a particular row in an SQLite database table?" }, { "role": "assistant", "content": "To delete a particular row in an SQLite database table, you can use the DELETE statement with a WHERE clause to specify the row to be deleted. For example: DELETE FROM...
bb45ad855c36c03c1e1167410f4aca73
[ { "role": "user", "content": "Is it possible to set a breakpoint that is not associated with any source code line in a GDB program?" }, { "role": "assistant", "content": "Yes, it is possible to set a breakpoint that is not associated with any source code line in a GDB program. For example, you c...
eaa3652c0f79260759735097794d25ab
[ { "role": "user", "content": "Write a C++ code to find the average of an array of integers." }, { "role": "assistant", "content": "#include <iostream>\n\nint calculateAverage(int array[], int n){\n int sum = 0; \n for (int i=0; i<n; i++){\n sum += array[i]; \n } \n int average...
0e98ff5b1ee8084a7cd8d21f3dad614c
[ { "role": "user", "content": "How can we encrypt a string in Python?" }, { "role": "assistant", "content": "We can encrypt a string in Python using the cryptography module. The cryptography module provides high level cryptographic primitives using the Fernet cipher. The Fernet cipher uses AES-12...
17c78757dd0df8a067f96a42c745667b
[ { "role": "user", "content": "What is the purpose of declaring a function as static in C++?" }, { "role": "assistant", "content": "The purpose of declaring a function as static in C++ is to restrict its visibility to only the translation unit in which it is declared. A static function can only b...
35dc282bc4c45fbc9b0e46d940aa67d4
[ { "role": "user", "content": "How to print the elements of a two-dimensional array in C?" }, { "role": "assistant", "content": "We can use nested loops to print the elements of a two-dimensional array in C. The outer loop iterates over the rows, while the inner loop iterates over the columns. Fo...
6f0d586c973c7d2372bddb64a5868f9f
[ { "role": "user", "content": "Using the following code, clean up the bugs and make sure the output functions correctly.\ndef example_func(lst):\n for element in lst:\n if (type(element) == int):\n lst.append(element + 5)\n return lst\n \nexample_func([1, 2, \"hello\"])" }, { "role":...
6937eb21453d22b77d3a06ef1050b702
[ { "role": "user", "content": "Write a C++ function to generate a random integer between 0 and 10." }, { "role": "assistant", "content": "#include <iostream> \n#include <cstdlib> \n#include <ctime> \nusing namespace std; \n\nint randomIntGenerator() \n{ \n // Setting the seed \n srand(time(0)...
17b31278fa51d2c0fc90d59472b50758
[ { "role": "user", "content": "Create a table to store customer information." }, { "role": "assistant", "content": "CREATE TABLE customers (\n id int NOT NULL AUTO_INCREMENT,\n name varchar(100) NOT NULL,\n email varchar(100) NOT NULL,\n phone varchar(20) NOT NULL,\n address varchar(200...
222b175e74febc562840ff00fa143a9c
[ { "role": "user", "content": "Create a class in Java named Puppy that has two instance variables, age and name and two methods, bark and sleep." }, { "role": "assistant", "content": "public class Puppy { \n // Instance Variables \n String name; \n int age; \n \n // Constructor \n publ...
93cdc34498271d6e11473f842382752c
[ { "role": "user", "content": "Parse the string and return the number of unique alphabets in the string.\nStringInput = \"apple\"" }, { "role": "assistant", "content": "int count = 0;\nfor (int i = 0; i < StringInput.length(); i++) {\n if ((StringInput.charAt(i) >= 'a' && StringInput.charAt(i) <...
1d42ec89d434a373939c520b11799527
[ { "role": "user", "content": "Write a shell script to print the top 3 most frequently used commands." }, { "role": "assistant", "content": "#!/bin/bash\n# Store all commands used in the last hour in command_list.\nhistory | tail -$(($(date +%H) * 60)) -n $(($(date +%M)+1)) | cut -d ' ' -f 5 > c...
13263b85c12cde5bda1fb4a94fcb9679
[ { "role": "user", "content": "Read the JSON string below and convert it into a dictionary.\njsonString = '{\"name\": \"John\", \"age\": 30, \"city\": \"New York\"}'" }, { "role": "assistant", "content": "import json\n\njsonObject = json.loads(jsonString)\ndictionary = dict(jsonObject)\nprint(dic...
f0f70dcdf53a9a8a7aa28aff1cc77aa9
[ { "role": "user", "content": "Implement a function that finds the maximum element in a given array.\narr = [45, 7, 0, 82, 23]" }, { "role": "assistant", "content": "def find_max_element(arr): \n max_element = arr[0] \n for index in range(1, len(arr)): \n if arr[index] > max_element:...
c76c69ff63f5ab094e79f33f42df504f
[ { "role": "user", "content": "Validate whether the string contains only alphabets or not.\nmyString = \"abc123\"" }, { "role": "assistant", "content": "def check_string_alphabets(myString):\n for character in myString:\n if (not character.isalpha()):\n return False\n retu...
117d64277ab951d27fa5176041f7d40c
[ { "role": "user", "content": "Rewrite the following code using ternary operator.\nnum1 = 5\nnum2 = 10\n\nif num1 < num2:\n print(\"num1 is smaller than num2\")\nelse:\n print(\"num1 is greater than or equal to num2\")" }, { "role": "assistant", "content": "num1 = 5\nnum2 = 10\n\nprint(\"nu...
aa51dec158fef12cde14e3de7a85042c
[ { "role": "user", "content": "Write a script to check if a given number is a palindrome or not.\ninputNumber = 121" }, { "role": "assistant", "content": "# Function to check whether the inputNumber is palindrome or not\ndef is_palindrome(inputNumber):\n\n # negative numbers are not palindrome\...
af81edaf6270482a33fc5003f73aac8b
[ { "role": "user", "content": "Edit the following code to remove the bugs.\ndef reverse_string(user_string): \n if len(user_string) == 0: \n return \"\" \n else: \n return reverse_string(user_string[1:]) + user_string[0] \n \nprint(reverse_string(“test”))" }, { "role": "assistant", "co...
5c68836e46950dbb389eba3a7b238b66
[ { "role": "user", "content": "What is the output of the following code?\nlist1 = ['a', 'b', 'c']\nlist2 = [1, 2, 3]\n\nfor x, y in zip(list1, list2):\n print(x * y)" }, { "role": "assistant", "content": "a\nbb\nccc" } ]
7e546ad0cddf7eaf73ef77c303612959
[ { "role": "user", "content": "Write a function to remove all whitespace characters from a given string.\nmyString = \"Hello World \"" }, { "role": "assistant", "content": "def remove_whitespaces(myString):\n return ''.join(myString.split())\n\nmyString = \"Hello World \"\nprint(remo...
1506545cdbc21aba60831938303ae2d7
[ { "role": "user", "content": "Edit the following code to add try catch block.\nx = \"5\"\ny = \"2\"\nsum = int(x) + int(y)\nprint(\"Sum of x and y is\", sum)" }, { "role": "assistant", "content": "x = \"5\"\ny = \"2\"\ntry:\n sum = int(x) + int(y)\n print(\"Sum of x and y is\", sum)\nexcept:...
c20d4d2b9d4bb335090ad35242eb4942
[ { "role": "user", "content": "Write a Python function that takes two lists of equal length and creates a dictionary of the elements in each list that have the same index.\nlist_one = [1, 2, 3, 4]\nlist_two = [\"a\", \"b\", \"c\", \"d\"]" }, { "role": "assistant", "content": "def list_dict(list_o...
3c44622a1af382e5503100b2845814a2
[ { "role": "user", "content": "Create a quick-sort algorithm in Python." }, { "role": "assistant", "content": "def quick_sort(arr):\n \"\"\"Sort a list of numbers in ascending order using the Quick-Sort algorithm\"\"\"\n if len(arr) == 0:\n return []\n\n pivot = arr[0]\n left_a...
4577ac2de961ffa72d7cc75bbeb88aa7
[ { "role": "user", "content": "Develop an algorithm to find the value of n where n is the index of the Fibonacci sequence." }, { "role": "assistant", "content": "def nth_fibonacci_number(n):\n \"\"\"Find the value of n where n is the index of the Fibonacci Sequence.\"\"\" \n if n < 2:\n ...
112bfbd44eb7bc58fd7d5a8b81f07df6
[ { "role": "user", "content": "Create a program that finds all the prime numbers less than or equal to a given number." }, { "role": "assistant", "content": "def find_primes(num):\n \"\"\"Find all the prime numbers less than or equal to a given number.\"\"\"\n primes = []\n for i in rang...
6e502d0133fa97f9d44e1a543acb930e
[ { "role": "user", "content": "Write a function that takes in a list of numbers and prints out the greatest number.\nlist = [8, 2, 14, 25]" }, { "role": "assistant", "content": "def find_greatest(list):\n \"\"\"Print out the greatest number from a list of numbers.\"\"\"\n greatest = list[0]...
End of preview. Expand in Data Studio

No dataset card yet

Downloads last month
14