[output] | num = 10 if num > 5: print('Yes') [instruction] | Modify the input so that the following Python program returns 'Yes' [input] | num = 10 if num > 5: print('No')
[output] | def sum_firstN_minusOne(X): total = 0 for i in range(len(X)-1): total += X[i] return total print(sum_firstN_minusOne(X)) [instruction] | Given the input list of size N, write a code to print out the sum of the first N-1 elements. [input] | X = [10, 20, 30, 40, 50]
[output] | def double_each(lst): return [x*2 for x in lst] print(double_each([1,10,20])) [instruction] | Output a list of each element in the input increase twice. [input] | [1,10,20]
[output] | A suitable machine learning model to perform topic clustering would be a clustering algorithm such as k-means, or a hierarchical clustering algorithm. These algorithms use the similarity or distance between each datapoint in order to group them into meaningful clusters. [instruction] | Formulate a suitable machine learning model to perform topic clustering. [input] |
[output] | #include <iostream> using namespace std; int main(){ int r, c, e; cout << "Input number of rows : "; cin >> r; cout << "Input number of columns : "; cin >> c; int M[r][c]; // Take input of elements for(int i = 0; i < r; ++i){ cout << "Enter elem [instruction] | Design a C++ program to read and display a matrix. [input] |
[output] | for n in range(10, -1, -1): print(n) [instruction] | Write a code to print out the list of the numbers from 0 to 10 in descending order. [input] |
[output] | class Foo(): def __init__(self, lst): self.lst = lst [instruction] | Edit the following Python class 'Foo' to accept a list of numbers upon instantiation. [input] | class Foo(): def __init__(self): self.lst = []
[output] | def mergeSort(arr): if len(arr) >1: mid = len(arr)//2 L = arr[:mid] R = arr[mid:] mergeSort(L) mergeSort(R) i = j = k = 0 while i < len(L) and j < len(R): if L[i] < R[j]: arr[k] = L[i] [instruction] | Generate a code to perform a Merge Sort on an unsorted array of numbers. [input] |
[output] | def count_larger(lst, k): count = 0 for i in lst: if i > k: count += 1 return count print(count_larger([10, 15, 20, 25], 15)) [instruction] | Create a function to find the number of elements in the list which have a value larger than the given number 'k'. [input] | [10, 15, 20, 25], k = 15
[output] | def find_union(A, B): return list(set(A).union(set(B))) A = [1, 2, 3, 4] B = [4, 5, 6, 7] print(find_union(A, B)) [instruction] | Write a code to print out the union of two sets using Python. [input] |
[output] | def firstIndex(str, char): index = -1 for i in range(len(str)): if (str[i] == char): index = i break return index result = firstIndex(str, char) print(result) # prints 4 [instruction] | Write a function that takes in a string and a character and returns the first index at which the character appears. [input] | str = 'Hello World' char = 'o'
[output] | def price_tag(cost, tax, discount): tax_amount = cost * tax discounted_price = cost + tax_amount - (discount * cost) return "Retail Price: $" + str(round(discounted_price, 2)) price_tag(cost, tax, discount) # returns "Retail Price: $7.20" [instruction] | Write a function to create a retail price tag given a cost, taxes and discounts. [input] | cost = 5 tax = 0.08 discount = 0.2
[output] | <form action="/search" method="get"> <input name="s" type="text" placeholder="Search..."> <input type="submit" value="Search"> </form> [instruction] | Write an HTML code snippet for creating a search box. [input] |
[output] | SELECT name, occupation FROM people WHERE age > 60; [instruction] | Write a SQL query to find the name and occupation of all people older than 60. [input] |
[output] | <?php $arr = ["Hello", "World", "My", "Name", "Is"]; //Finding the longest word in the array $longestWord = ""; foreach($arr as $word) { if (strlen($word) > strlen($longestWord)) { $longestWord = $word; } } echo "The longest word is: " . $longestWord; ?> [instruction] | Write a PHP code for finding the longest word in an array of strings. [input] | $arr = ["Hello", "World", "My", "Name", "Is"];
[output] | SELECT AVG(salary) FROM employees WHERE experience = 10; [instruction] | Write an SQL query to find the average salary of all the employees with 10 years of experience. [input] |
[output] | public class MatrixProduct { // Method for matrix multiplication static int[][] multiplyMatrix(int[][] matrix1, int[][] matrix2) { int rowsInA = matrix1.length; int columnsInA = matrix1[0].length; // same as rows in B [instruction] | Write a Java program for computing the product of two matrixes. [input] |
[output] | <select> <option value="Apple">Apple</option> <option value="Orange">Orange</option> </select> [instruction] | Write an HTML code for creating a dropdown menu with two options, "Apple" and "Orange". [input] |
[output] | <html> <head> <title>Table example</title> </head> <body> <table border = "1"> <tr> <td>Row 1, Column 1</td> <td>Row 1, Column 2</td> </tr> <tr> <td>Row 2, Column 1</td> <td>Row 2 [instruction] | Write an HTML program to display an output as a table. [input] |
[output] | A class in Java consists of the following components: fields (state of the object), constructors (constructs an object), methods (behavior of the object), nested classes and interfaces (classes that are associated with the class in which it is declared). The fields and methods are collectively calle [instruction] | What are the components of a class in Java? [input] |
[output] | import tensorflow as tf x = tf.constant([[1,2],[3,4]], dtype=tf.int32) y = tf.constant([[5,6],[7,8]], dtype=tf.int32) #Sum operation z = tf.add(x, y) #Run in session with tf.Session() as session: print(session.run(z)) # Output: # [[ 6 8] # [10 12]] [instruction] | Write a TensorFlow program to compute the sum of two tensors. [input] | x = [[1,2],[3,4]] y = [[5,6],[7,8]]
[output] | function countOccurences(numList: number[], num: number): number { let count = 0; for (let i = 0; i < numList.length; i++) { if (numList[i] === num) count++; } return count; } [instruction] | Convert the following JavaScript function to TypeScript. [input] | function countOccurences(numList,num) { let count = 0; for (let i = 0; i < numList.length; i++) { if (numList[i] === num) count++; } return count; }
[output] | The HTML tags should be closed properly. The correct code should be: <h1>Welcome</h1> <b>This is a sample page</b> [instruction] | Guess what is wrong with the following HTML code. [input] | <h1>Welcome<h1> <b>This is a sample page<b>
[output] | The four main programming paradigms are procedural, object-oriented, functional, and logical. [instruction] | Name the four programming paradigms. [input] |
[output] | def bubbleSort(arr): # Traverse through all array elements for i in range(len(arr)): # Last i elements are already in place for j in range(0, len(arr)-i-1): # traverse the array from 0 to n-i-1 # Swap if the element found is greater [instruction] | Write the code for the following sorting algorithm. [input] | Bubble Sort
[output] | public class SumOfEle{ public static void main(String[] args) { // creating a two-dimensional array int[][] arr = { {2, 3, 8}, {4, 5, 1}, {7, 0, 6} }; // Creating an int variable to store the value. int sum = 0; [instruction] | Using Java, write the code to calculate the sum of elements in a two-dimensional array. [input] | int[][] arr = { {2, 3, 8}, {4, 5, 1}, {7, 0, 6} };
[output] | function reverseString(str) { return str.split('').reverse().join(''); } let str = "JavaScript"; console.log(reverseString(str)); // Output: tpircSavaJ [instruction] | Write a JavaScript program to accept a string and display the characters in reverse order. [input] |
[output] | React's official debugging tool, the React Developer Tools, is a great plugin for debugging React applications. It is available for both Chrome and Firefox, and provides detailed information about the component hierarchy, current props and state of the application, and detailed performance metrics. [instruction] | Suggest a plugin or software that can be used to debug a React application. [input] |
[output] | let x = 1; let y = 2; switch (x) { case 1: if (y === 2) { console.log('x is 1 and y is 2'); break; } default: console.log('No match'); } [instruction] | Create a switch statement in JavaScript to compare two values. [input] |
[output] | public int binarySearch(int[] arr, int element){ int low = 0; int high = arr.length - 1; while(low <= high){ int mid = (low + high) / 2; if(arr[mid] == element) return mid; else if(arr[mid] > element) high = mid - 1; else [instruction] | Suggest an algorithm to search an element in a sorted array using Java. [input] |