[output] | import json input_json = { "name": "John Doe", "age": 28, "country": "United States" } def get_name(json): json_dict = json.loads(json) name = json_dict['name'] return name if __name__ == '__main__': print(get_name(input_json)) [instruction] | Return the "name" field of the JSON object given below. [input] | { "name": "John Doe", "age": 28, "country": "United States" }
[output] | CREATE TABLE books ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), author VARCHAR(255), date DATE ); [instruction] | Create a database schema for a books table with id, name, author, and date fields. [input] |
[output] | import lxml.html input_html = ''' <form> <input name="user_id" type="text" id="user_id" value="123456"> <input name="name" type="text" id="name" value="John Doe"> <input name="email" type="text" id="email" value="john@example.com"> <input name="password" type="password" id="password" va [instruction] | Parse the following HTML string and return the list of id's. [input] | <form> <input name="user_id" type="text" id="user_id" value="123456"> <input name="name" type="text" id="name" value="John Doe"> <input name="email" type="text" id="email" value="john@example.com"> <input name="password" type="password" id="password" value="password123"> </form>
[output] | Array = [] for num in range(2,101): if all(num % i != 0 for i in range(2,num)): Array.append(num) print(Array) [instruction] | Create an array of prime numbers between 0 and 100 and print them out. [input] |
[output] | def find_max_of_three(a, b, c): """ This function finds the maximum of three numbers """ return max(a, b, c) if __name__ == '__main__': a = 6 b = 7 c = 4 print(find_max_of_three(a, b, c)) [instruction] | Create a function that takes 3 parameters and returns the maximum of them. [input] | 6, 7, 4
[output] | def rotate_array(arr, n): """ This function rotates a list of elements by a certain number of times """ return arr[n:] + arr[:n] if __name__ == '__main__': arr = [1, 2, 3, 4] n = 2 print(rotate_array(arr, n)) [instruction] | Rotate a list of elements by a certain number of times. [input] | [1, 2, 3, 4], 2
[output] | [] [instruction] | Output a list of the elements that appear both in list a and list b. [input] | list a: [1, 3, 5, 7, 9] list b: [2, 4, 6, 8]
[output] | class Student: def __init__(self, name, grade): self.name = name self.grade = grade def getName(self): return self.name def getGrade(self): return self.grade [instruction] | Create a class in Python that contains the following methods: [input] |
[output] | function printSquare(num){ if (num < 0){ throw new Error('Negative number is not allowed'); } console.log(num * num); } [instruction] | Edit the following JavaScript function to throw an error when the user enters a negative number. [input] | function printSquare(num) { console.log(num * num); }
[output] | def capitalize(string): return string.capitalize() [instruction] | Construct a function to convert a string of length one to a capitalized version. [input] |
[output] | ^\d{5}(?:[-\s]\d{4})?$ [instruction] | Construct a regex expression that matches a valid US zip code. [input] |
[output] | def remove_non_alphanumeric(string): return ''.join(c for c in string if c.isalnum()) remove_non_alphanumeric("Hello world!") [instruction] | Construct a function that removes any non-alphanumeric characters from a string. [input] | Hello world!
[output] | SELECT * FROM students ORDER BY id DESC; [instruction] | Write a SQL query that reverses the order of entries in table 'students'. [input] |
[output] | for (i = 0; i < 10; i++) [instruction] | Identify the loop control statement used in the below program for (i = 0; i < 10; i++) { printf("%d ", i); } [input] |
[output] | The code implements Bubble Sort, which is a type of comparison sorting algorithm. It works by repeatedly swapping adjacent elements if they are in the wrong order. [instruction] | What type of sorting algorithm does the following Python code implement? def sort(nums): for i in range(len(nums)): for j in range(i+1, len(nums)): if nums[j] < nums[i]: nums[j], nums[i] = nums[i], nums[j] [input] |
[output] | The Big O notation for the algorithm is O(n^2). This indicates that the time complexity is proportional to the square of n. [instruction] | What is the Big O notation of the algorithm below? def myfunc(n): total = 0 for i in range(n): for j in range(n): total += 1 return total [input] |
[output] | def printSquare(): for i in range(10): print(i**2) [instruction] | Edit the below program to print the square of numbers from 0 to 10. def printSquare(): for i in range(10): print(i) [input] |
[output] | def Fibonacci(n): a = 0 b = 1 if n < 0: print("Incorrect input") elif n == 0: return a elif n == 1: return b else: for i in range(2,n): c = a + b a = b b = c return b # Driver Code print("Fibonacci Sequence:") for i in range(50): print(Fibonacci(i), end = ' [instruction] | Write a code snippet to display the Fibonacci sequence up to 50 numbers. [input] |
[output] | The given implementation is of a Linked List data structure. Linked Lists are a type of linear data structure which consists of nodes, with each node pointing to the next node in the list. [instruction] | Identify the data structure used in the given implementation. class Node: def __init__(self, value): self.value = value self.next = None [input] |
[output] | The output of the code will be 0, 1, 2, 3, 4, 5. The loop will run until the condition (x <= 5) is satisfied and print out the current value of x each time. [instruction] | What is the output of the following JavaScript code? let x = 0; while(x <= 5) { console.log(x); x++; } [input] |
[output] | This for loop will execute the code within it 10 times. On each iteration of the loop, the variable i will be incremented by 1. The starting value of variable i will be 0, then the loop condition will check if the variable i is less than 10. If the condition is true, the code in the loop will execut [instruction] | Explain what happens when executing this C++ for loop. [input] | for(int i=0;i<10;i++){ cout << i << endl; }
[output] | The code contained a syntax error. In the second line of the code, the operator being used was "b" instead of "+". The correct line should be "int c = a + b;". This error was causing the program to return the wrong value, as it was attempting to perform the wrong calculation. [instruction] | Debug this Java code and explain what was wrong. [input] | public static int add(int a, int b){ int c = a b; return c; }
[output] | This program has a runtime complexity of O(n), where n is the number of items in the list. This is because the time taken to complete the program increases linearly with the number of items in the list. [instruction] | Find the runtime complexity of this Python program. [input] | def EvenOrOdd(items): if len(items) == 0: return 0 even_count = 0 for item in items: if item % 2 == 0: even_count += 1 return even_count
[output] | def get_length(text): counter = 0 for i in text: counter += 1 return counter res = get_length(text) print(res) [instruction] | Write a function to get the length of a given string without using any built-in function. [input] | text = "Hello world!"
[output] | class Node: def __init__(self, data): self.data = data self.next = None [instruction] | Create a Node class with two properties: 'data' and 'next'. [input] |
[output] | total = 0 for i in arr: total += i print(total) [instruction] | How would you sum up the elements in an array represented by an integer array? [input] | arr = [10, 15, 25, 20]
[output] | def matrix_sum(A, B): m = len(A) n = len(A[0]) C = [[0 for i in range(n)] for j in range(m)] for i in range(m): for j in range(n): C[i][j] = A[i][j] + B[i][j] return C A = [[1, 2], [4, 5]] B = [[3, 6], [7, 8]] res = matrix_sum(A, B) print(res [instruction] | Compute the sum of two matrices of size m x n. [input] | A = [[1, 2], [4, 5]] B = [[3, 6], [7, 8]]
[output] | def find_length(string): count = 0 for char in string: count += 1 print(message, count) return count [instruction] | Modify the function to include a message about the length of the string. [input] | message = "The length of the string is:"
[output] | git branch feature-X git checkout feature-X [instruction] | Create a new branch in Git with the name "feature-X" and switch to it. [input] |
[output] | def select_rows(df, col_1, value): return df[df[col_1] == value] [instruction] | Build a function in Python for selecting all rows from a Pandas DataFrame where a column value is equal to a given value. [input] | df = pd.DataFrame({'A':[1, 2, 3, 4, 5], 'B':[2, 3, 4, 5, 6], 'C':[3, 4, 5, 6, 7], 'D':[4, 5, 6, 7, 8]}) col_1 = 'A' value = 3