[output] | for (let i = 1; i <= 10; i++) { console.log(`3x${i}=${3*i}`); } [instruction] | Write a JavaScript code to print out the multiplication table of 3. [input] |
[output] | public class Rectangle { int length; int breadth; Rectangle(int l, int b) { length = l; breadth = b; } int calculateArea() { return length * breadth; } } [instruction] | Create a class in Java for a rectangle shape with length and breadth as attributes. [input] |
[output] | def cov(list1, list2): mean1 = sum(list1)/len(list1) mean2 = sum(list2)/len(list2) total = 0 for i in range(len(list1)): total += (list1[i] - mean1)*(list2[i] - mean2) return total/len(list1) [instruction] | Make a function in Python which calculates the covariance between two given lists. [input] | list1: [1, 2, 3, 4, 5] list2: [3, 4, 2, 4, 5]
[output] | =50*2 [instruction] | Write a formula in Excel to calculate the total cost of a trip given the cost and quantity. [input] | Cost of hotel: $50 Quantity of rooms: 2
[output] | div { width: 500px; height: 400px; } [instruction] | Write a CSS style to make a <div> element of width 500px and height 400px. [input] |
[output] | SELECT * FROM USERS WHERE gender = 'Male'; [instruction] | Generate a SQL query to retrieve all records from the USERS table where the gender is 'Male'. [input] |
[output] | function createArray(string) { return string.split(','); } [instruction] | Create a method in JavaScript that takes a comma-separated list of values as an argument and returns an array containing those values. [input] |
[output] | LOAD value1 ADD value2 STORE result [instruction] | Write an assembly language code to find the sum of two values stored in memory. [input] |
[output] | The purpose of this JavaScript code is to create a comma-separated string from an array of strings. The code uses the reduce function to concatenate the strings in the array with a comma and create a new string beginning with the string 'All students: '. The resulting string is stored in the nameStr [instruction] | What is the purpose of this JavaScript code? [input] | const studentNames = ["John", "Paul", "Ringo", "George"]; let nameString = studentNames.reduce((string, name) => { return string + name + ","; }, 'All students: ');
[output] | let numbers = [1, 2, 3] function sumArray(arr) { let total = 0; for(let i = 0; i < arr.length; i++) { total += arr[i]; } return total; } console.log(sumArray(numbers)); [instruction] | Modify the following code to return the sum of an array [input] | let numbers = [1, 2, 3]
[output] | # list of numbers list = [20, 10, 4, 45, 99] # printing the greatest number print(max(list)) [instruction] | Here's some Python code that finds the smallest number in a list. Edit it to find the greatest number in a list. [input] | # list of numbers list = [20, 10, 4, 45, 99] # printing the smallest number print(min(list))
[output] | for i in range(0, 13, 4): print(i) [instruction] | Write a for loop that prints out the series: 0, 4, 8, 12 [input] |
[output] | char[] array = str.toCharArray(); [instruction] | Convert the following string to an array of characters in Java. [input] | String str = "Hello World!"
[output] | String s = "Hello World!"; int count = 0; for (int i=0; i < s.length(); i++) { if (s.charAt(i) == 'e') { count++; } } System.out.println("The number of occurrences of character 'e' in the string is: " + count); [instruction] | Modify the following program to print the number of occurrences of the character e in string s. [input] | String s = "Hello World!"
[output] | int sum(int x, int y) { return x + y; } [instruction] | Write a function that finds the sum of two digits in C. [input] |
[output] | A data structure that can be used to store words of the same length is a Trie. A Trie is a tree-based data structure which stores characters of strings as nodes in a tree. The advantage of using a Trie for storing words of the same length is that it is an efficient data structure for retrieving word [instruction] | What data structure can be used to store words of the same length? [input] |
[output] | class ListNode: def __init__(self, data): self.data = data self.next = None class LinkedList: def __init__(self): self.head = None def is_empty(self): return self.head == None # Other method implementations go here [instruction] | So you need to design a class for a Linked List. [input] |
[output] | true [instruction] | You need to read a code and check if it uses the best practices for writing code. Output true if it does, false if it does not. [input] | def quick_sort(arr): if len(arr) < 2: return arr else: pivot = arr[0] less = [i for i in arr[1:] if i <= pivot] greater = [i for i in arr[1:] if i > pivot] return quick_sort(less) + [pivot] + quick_sort(greater)
[output] | new_dict = {key: value ** 2 for key, value in original_dict.items()} [instruction] | Create a dictionary using comprehension technique in Python. [input] | original_dict = {'a':1, 'b':2, 'c':3, 'd':4}
[output] | list_divisible_by_5 = [x for x in range(0, 26) if x%5 == 0] [instruction] | Create a list of all numbers that are divisible by 5 between 0 and 25. [input] |
[output] | import numpy as np size = 5 # Create an array of size 5 arr = np.random.randint(100, size = (size)) print (arr) [instruction] | Generate a random array of size n in Python. [input] | Size of array: 5
[output] | for i in range(5, 1, -1): print(i) [instruction] | Create a loop to print the numbers in reverse order from 5 to 2. [input] |
[output] | Neural n [instruction] | Given two parameters a and b, return a substring starting from index a and ending at index b. [input] | String: "Neural networks are powerful algorithms" Parameters: a = 0, b = 7
[output] | Fahrenheit = 68 [instruction] | Using Python, write a piece of code to convert Celsius temperatures to Fahrenheit. [input] | Celsius: 20
[output] | Linked List: 1->4->3->2->5 [instruction] | Given a linked list, swap the positions of the two nodes in the list. [input] | Linked List: 1->2->3->4->5
[output] | 1 1 2 3 5 [instruction] | Write a method to print the first n numbers in the Fibonacci series. [input] | n = 5
[output] | \^awesome\s|\^data\s|\^scoring\s [instruction] | Given a string, you need to write a regular expression that finds all the words that start with a caret (^) symbol. [input] | String: "^awesome ^data ^scoring"
[output] | SELECT grade, AVG(score) FROM students GROUP BY grade [instruction] | Construct a SQL query to group students by the grade they got, and calculate the average score. [input] |
[output] | The nimble brown fox leaps over the sluggish dog. [instruction] | Find the most common word in the following paragraph and replace it with a synonym. [input] | The quick brown fox jumps over the lazy dog.
[output] | 3 [instruction] | Compute the GCD of two numbers without using any built-in functions from your language. [input] | Number1: 9 Number2: 6