[output] | An API (Application Programming Interface) is a set of programming instructions and standards used for interacting with a software application or web service. It generally enables a developer to access specific features of an application or web service, such as data or functionality, to build integr [instruction] | Describe the purpose of an API. [input] |
[output] | filtered = list(filter(lambda x : len(x) < 5, arr)) [instruction] | Write a lambda expression to select all the strings from a given array whose length is less than 5. [input] | arr = ["Hello", "Bye", "Morning", "Evening", "Hi", "Bye Bye"]
[output] | Relational Operator. [instruction] | Identify the type of operator in the expression. [input] | Expression: 7 > 5
[output] | def compare_strings(s1, s2): count = 0 for i in range(min(len(s1), len(s2))): if s1[i] != s2[i]: count += 1 return count [instruction] | Write a function to compare two strings and return the number of character positions at which the strings in the two strings differ from each other. [input] | str1 = "apple" str2 = "animal"
[output] | UPDATE employees SET employee_name='John' WHERE employee_id=101; [instruction] | Write a SQL query that updates the name of a specified employee in the 'employees' table. [input] | employee_id: 101, employee_name: John
[output] | def calculateSum(arr): sum = 0 for num in arr: sum += num return sum print(calculateSum([2, 3, 4, 5])) [instruction] | Write a Python program for calculating the sum of a given array of numbers. [input] | [2, 3, 4, 5]
[output] | public class Car { private String make; private int speed; private String color; public Car() { this.make = "default"; this.speed = 100; this.color = "black"; } public Car(String make, int speed, String color) { this.make = make; [instruction] | Create an object-oriented programming class in Java named "Car" with three private instance variables "make", "speed" and "color". [input] |
[output] | SELECT * FROM Students ORDER BY grade; [instruction] | Write a basic SQL query to retrieve all students from the table "Students" and order them by their "grade". [input] |
[output] | In JavaScript, error handling can be done with try...catch statements. The syntax of the try...catch statement consists of a try block followed by one or more catch clauses. The try block contains the code that may throw an error, whereas the catch block contains the code that will be executed if an [instruction] | How do you perform error handling in JavaScript? [input] |
[output] | public static bool AreAnagrams(string string1, string string2) { if (String.Concat(string1.OrderBy(c => c)) == String.Concat(string2.OrderBy(c => c))) { return true; } else { return false; } } bool result = AreAnagrams("listen", "silent"); [instruction] | Compare two strings in C# and return a Boolean indicating whether they are anagrams. [input] | string1 = "listen"; string2 = "silent"
[output] | string output = string3.Replace(string1, string2); // Output: One apricot a day keeps the doctor away [instruction] | Given two strings, find and replace the first instance of the string1 with string2. [input] | string1 = "apple"; string2 = "apricot"; string3 = "One apple a day keeps the doctor away"
[output] | SELECT * FROM Employees ORDER BY Salary DESC; [instruction] | Write an SQL query to select all records from a table named "Employees" and order the records by their salary in descending order. [input] |
[output] | function toFahrenheit(celsius) { return celsius * 9/5 + 32; } function toCelsius(fahrenheit) { return (fahrenheit - 32) * 5/9; } [instruction] | Edit the following JavaScript function to convert Celsius to Fahrenheit. [input] | function toFahrenheit(celsius) { return celsius * 9/5 + 32; }
[output] | def cube(number): return number**3 [instruction] | Define a function in Python that takes a number as an argument and returns its cube. [input] |
[output] | .container { display: grid; grid-template-columns: 1fr 1fr 1fr; } [instruction] | Design a CSS grid container with 3 columns of equal size. [input] |
[output] | # Using Python: # Imports import mysql.connector # Database connection mydb = mysql.connector.connect( host="<hostname>", user="<username>", passwd="<password>", database="<database_name>" ) # Query mycursor = mydb.cursor() mycursor.execute("SELECT * FROM customers") # Fetch res [instruction] | Build a web service that returns a list of all the customers in a MySQL database. [input] |
[output] | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Number Guessing Game</title> <style> * { padding: 0; margin: 0; } #guessing-game-container { [instruction] | Create an interface for a number guessing game using HTML, CSS, and JavaScript. [input] |
[output] | # Using Python: plain_text = "Hello" # Simple substitution encryption alphabet = ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z') encrypted_text = "" for plain_letter in plain_text: if plain_letter in alphabet: encrypted_letter [instruction] | Create a program to encrypt a given text using any encryption technique. [input] | Hello
[output] | # Using Java: public static List<String> getWords(String sentence) { List<String> words = new ArrayList<>(); String[] wordsArray = sentence.split("\\s+"); for (String word : wordsArray) { words.add(word); } return words; } [instruction] | Create a function in Java to take a sentence as input and return a list of all the words in the sentence. [input] | I am a student
[output] | SELECT * FROM table WHERE department = 'sales'; [instruction] | Construct an SQL query to find all records where the column ‘department’ equals ‘sales’. [input] |
[output] | # Using Python: import xml.etree.ElementTree as ET xml_string = "<employee name="John" id="123" position="Manager" dept="Sales" />" # Parse the XML root = ET.fromstring(xml_string) # Iterate through the child nodes for child in root: # Print all the attributes for (name, value) in child [instruction] | Parse a given XML string and print all the attributes present in the 'employee' tag. [input] | <employee name="John" id="123" position="Manager" dept="Sales" />
[output] | # Using JavaScript: let boolean = Math.random() >= 0.5; console.log(boolean); [instruction] | Generate a random boolean value using JavaScript. [input] |
[output] | # Using Bash: # Print the environment variables for var in $(env); do echo "$var"; done [instruction] | Write a shell script to print all the environment variables in use. [input] |
[output] | arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] [instruction] | Populate an array with numbers from 1 to 10 in Python. [input] |
[output] | 10.times do puts “Hello World” end [instruction] | Design a loop in Ruby that prints "Hello World" 10 times. [input] |
[output] | function sumArray(arr) { if (arr.length === 0) { return 0; } return arr[0] + sumArray(arr.slice(1)); } let result = sumArray(arr); console.log(result); // 21 [instruction] | Construct a recursive function in JavaScript that calculates the total sum of an array. [input] | arr = [1, 2, 3, 4, 5, 6]
[output] | <?php $arr = [[1,2], [3,4]]; function printArray($arr) { foreach($arr as $row) { foreach($row as $element){ echo $element." "; } echo "<br>"; } } printArray($arr); ?> [instruction] | Write a PHP program that prints the contents of a multidimensional array. [input] | arr = [[1,2], [3,4]]
[output] | public class Main { public static void main(String[] args) { int[] arr = {3,4}; int num1 = arr[0]; int num2 = arr[1]; int result = num1 * num2; System.out.println(result); } } [instruction] | Create a program in Java that takes an array with two integers as input and prints the multiplication of those two input integers. [input] | arr = [3, 4]
[output] | let string = "This is a test sentence"; let wordsArray = string.split(" "); let frequencyMap = {}; wordsArray.forEach(word => { frequencyMap[word] = frequencyMap[word] ? frequencyMap[word] + 1 : 1; }); console.log(frequencyMap); // Output: {This: 1, is: 1, a: 1, test: 1, sentence: 1} [instruction] | Determine the frequency of each word in a sentence using a hashmap in JavaScript. [input] | s = "This is a test sentence"
[output] | def bubbleSort(array): n = len(array) for i in range (n): for j in range(0, n-i-1): if array[j] > array[j+1] : array[j], array[j+1] = array[j+1], array[j] arr = [64, 34, 25, 12, 22, 11, 90] bubbleSort(arr) print ("Sorted array is:") for i in range(n): print ("%d" %arr[i]), [instruction] | Construct a bubblesort algorithm in Python. [input] |