[output] | const App = () => { const [name, setName] = useState('John'); const handleChange = (e) => { setName(e.target.value); }; return ( <div> <input value={name} onChange={handleChange} /> </div> ); } [instruction] | Rewrite a react class component as a functional component. [input] | class App extends React.Component { constructor(props) { super(props); this.state = { name: 'John' }; } handleChange = (e) => { this.setState({ name: e.target.value }); }; render() { return ( <div> <input value={this.state.name} onChange=
[output] | SELECT name, birthdate FROM employees; [instruction] | Create a SQL query to retrieve the names and birthdates of all employees in a table called "employees". [input] |
[output] | Negative sentiment [instruction] | Categorize the following sentence as either positive or negative sentiment: "I had the worst experience with this product". [input] | I had the worst experience with this product
[output] | SELECT AVG(TIMEDIFF(session_end_time, session_start_time)) AS Average_Time_Spent FROM customers; [instruction] | Create a MySQL query to calculate the average length of time spent by customers on your website. [input] |
[output] | Math.round(3.7); [instruction] | Write a JavaScript code snippet to round a number 3.7 to nearest integer. [input] |
[output] | <html> <body> <form> <input type="text" name="box1" /> <input type="text" name="box2" /> <input type="text" name="box3" /> </form> </body> </html> [instruction] | Create a HTML page containing a form with three input boxes. [input] |
[output] | def count_occurrences(string1, string2): # Initialize count to 0 count = 0 # Iterate over the first string for i in range(len(string1)): # Slice the element from i to length of second string temp = string1[i: i + len(string2)] # If sliced strin [instruction] | Write a function that takes two strings and returns the total number of occurrences of the second string in the first. [input] | string1 = "hello world" string2 = "world"
[output] | A hash table is a data structure that stores data in an associative manner. It is typically implemented using an array combined with a hash function. The purpose of the hash function is to map data to array indices and facilitate efficient searches. Hash tables are important as they provide fast acc [instruction] | What is a hash table and explain why it is an important data structure? [input] |
[output] | import sqlite3 # Create a connection to the db conn = sqlite3.connect('database.db') c = conn.cursor() # Define a function that queries the db and fetches the required table def query_db(table): query = f"SELECT * FROM {table}" c.execute(query) all_rows = c.fetchall() return all_rows # Create [instruction] | Create a basic API that queries a database and returns a result in a certain format [input] |
[output] | The product of 16 and 4 is 64. [instruction] | What is the product of 16 and 4? [input] |
[output] | <?php echo date("d-F-Y H:i:s"); ?> [instruction] | Write a PHP script to print the current date and time in the following format: '27-April-2020 05:30:00'. [input] |
[output] | def find_sum(x, y, z): return x + y + z [instruction] | Edit the code to add an additional parameter. [input] | def find_sum(x, y): return x + y
[output] | def compute_squared(x, y=0, z=0): '''This function computes the sum of the squared values of x, y, and z.''' return x ** 2 + y ** 2 + z ** 2 [instruction] | For the given code, fill the missing values for the parameters. [input] | def compute_squared(x, y=?, z=?): '''This function computes the sum of the squared values of x, y, and z.''' return x ** 2 + y ** 2 + z ** 2
[output] | def compound_calculation(x, y, z=1.1): '''This function calculates the compound amount at the given rate.''' return (x + y) * z [instruction] | Fill the missing values below to make the function work properly. [input] | def compound_calculation(x, y, z=?): '''This function calculates the compound amount at the given rate.''' return (x + y) * z
[output] | Yes, the code uses the Iterator pattern to loop over the elements of the list. [instruction] | Are there any recognizable design patterns used in the code? [input] | def double_all(numbers): ''' This function takes in a list of numbers as an argument and returns a new list with all the numbers doubled. ''' doubled_numbers = [] for number in numbers: doubled_numbers.append(number * 2) return doubled_numbers
[output] | def is_even(number): '''This function should return true if the number is even and false if the number is odd.''' return (number % 2) == 0 [instruction] | Complete the function to correctly check if a number is even. [input] | def is_even(number): '''This function should return true if the number is even and false if the number is odd.''' # TODO
[output] | def scale_value(x, factor): '''This function will scale the given number by the given factor.''' return x * factor [instruction] | Create a function to scale a number by the given factor. [input] | factor = 0.5
[output] | def find_common_elements(list_1, list_2): '''This function will find the common elements in two lists.''' return [val for val in list_1 if val in list_2] [instruction] | Create a function to find common elements in two lists. [input] | list_1 = [1, 2, 3] list_2 = [2, 3, 4]
[output] | def is_substring(string_1, string_2): '''This function takes two strings and returns a boolean indicating whether string_2 is a substring of string_1.''' return string_2 in string_1 [instruction] | Create a function to determine whether one string is a substring of another. [input] | string_1 = "abcdefgh" string_2 = "efg"
[output] | def swap_elements(lst, index_1, index_2): '''This function takes in a list and two indices and swaps the elements at the given indices.''' lst[index_1], lst[index_2] = lst[index_2], lst[index_1] return lst [instruction] | Create a function that takes in a list and an index and swaps the elements at the given indices. [input] | list = [1, 2, 3, 4] index_1 = 0 index_2 = 2
[output] | """ Write a code which generates the Fibonacci sequence """ def generate_fibonacci_sequence(n): a = 0 b = 1 if n == 1: print(a) else: print(a) print(b) for i in range(2,n): c = a + b a = b b = c [instruction] | Write a code which generates the Fibonacci sequence. [input] |
[output] | """ Create a program to calculate the area and the perimeter of a rectangle """ def area_perimeter(length, width): area = length * width perimeter = 2 * (length + width) return area, perimeter if __name__ == '__main__': print(area_perimeter(4, 5)) [instruction] | Create a program to calculate the area and the perimeter of a rectangle. [input] | length = 4 width = 5
[output] | """ Code a function to solve the Tower of Hanoi puzzle """ def tower_of_hanoi(n, source, aux, dest): if n == 1: print("Move disk 1 from rod", source, "to rod", dest) return tower_of_hanoi(n-1, source, dest, aux) print("Move disk", n, "from rod", source, "to rod", dest [instruction] | Code a function to solve the Tower of Hanoi puzzle. [input] |
[output] | """ Sort an array of characters in alphabetic order """ def sort_alphabetically(arr): arr.sort() return arr if __name__ == '__main__': print(sort_alphabetically(['x', 'q', 'b', 'j'])) [instruction] | Sort an array of characters in alphabetic order. [input] | ['x', 'q', 'b', 'j']
[output] | """ Create a program which calculates the median of an array """ def median(arr): n = len(arr) arr.sort() if n % 2 == 0: return (arr[n//2] + arr[n//2-1])/2 else: return arr[n//2] if __name__ == '__main__': print(median([3, 5, 4, 1, 7])) [instruction] | Create a program which calculates the median of an array. [input] | [3, 5, 4, 1, 7]
[output] | function largestElement(arr){ var max = arr[0]; for(var i=1;i<arr.length;i++){ if(arr[i]>max){ max=arr[i]; } } return max; } [instruction] | Construct a Javascript program to return the largest element of an array. [input] |
[output] | def merge(list1, list2): mergedList = [] for x,y in zip_longest(list1,list2): mergedList.extend([x,y]) return mergedList [instruction] | Create a Python program to merge two lists by alternating elements. [input] | list1 = [2, 3, 5, 7]; list2 = [4, 8, 10];
[output] | public static void sortArray(int[] array) { int temp; for (int i = 0; i < array.length; i++) { for (int j = i + 1; j < array.length; j++) { if (array[i] > array[j]) { temp = array[i]; array[i] = array[j]; array[j] = te [instruction] | Edit the following Java program to sort a given array. [input] | int[] array={16, 5, 1, 8, 10};
[output] | #include <stdio.h> int main() { int i, j, flag; printf("Prime numbers between 1 to 100 are: \n"); for(i=2; i<=100; i++) { flag = 0; for(j=2; j<i; j++) { if(i%j == 0) { flag = 1; break; [instruction] | Compile a C program to display the prime numbers from 1 to 100. [input] |
[output] | [1, 2, 3, 4, 5] [instruction] | Rearrange the elements of the array [3, 1, 2, 5, 4] in ascending order. [input] | [3, 1, 2, 5, 4]