[output] | The JSON given represents a basic object data type. [instruction] | Which basic data type is represented by the following JSON? {"name": "John", "age": 30} [input] |
[output] | if [ $k = true ]; then echo "k is true" else echo "k is false" fi [instruction] | Create a script that takes an input variable k, and prints out "k is true" if k is true, and "k is false" if k is false. [input] | k = 2 < 5
[output] | int add(int a, int b) { return a + b; } [instruction] | Write a method to return the sum of two integers a and b. [input] | a = 2, b = 8.
[output] | var array = [Int](repeatElement(0, count: 5)) [instruction] | Create an array of integers in Swift with length 5. [input] |
[output] | SELECT name FROM People WHERE salary > 60000; [instruction] | Write a SQL query that prints the names of all the people with a salary greater than $60000. [input] | SELECT name FROM people WHERE salary > 60000
[output] | int a = 10; int b = 20; Console.WriteLine("The result is " + (a + b).ToString()); [instruction] | Modify the following code to print out "The result is 30". [input] | int a = 10 int b = 20 Console.WriteLine("The result is " + a + b)
[output] | SELECT name FROM People WHERE yearOfBirth = 1990; [instruction] | Create an SQL query that returns the names of all the people born in the year 1990. [input] | SELECT name FROM People WHERE yearOfBirth = 1990
[output] | int result = (int)Math.pow(3, 4); [instruction] | Calculate the value of 3^4 using Java code. [input] |
[output] | class Number: def __init__(self, number): self.number = number self.square = number * number self.cube = number * number * number [instruction] | Create a class to store the number, its square and its cube. [input] |
[output] | def longest_palindrome(text): longest_palindrome = "" for i in range(len(text)): for j in range(len(text), i, -1): substring = text[i:j] if substring == substring[::-1] and len(substring) > len(longest_palindrome): longest_palindrome = substring return longest_palindrom [instruction] | Make a program that takes in a non-empty string and finds its longest palindrome. [input] |
[output] | def fibonacci(n): if n <= 1: return n else: return fibonacci(n-1) + fibonacci(n-2) [instruction] | Create an algorithm to produce a Fibonacci number. [input] |
[output] | def solve_linear_equation(a, b): return -b/a [instruction] | Create a method to solve a linear equation ax + b = 0. [input] | a = 2, b = 4
[output] | def parse_string(expr): root = Node(expr[0]) current_node = root for i in range(1, len(expr), 2): node = Node(expr[i]) current_node.right = node node.left = current_node current_node = node return root class Node: def __init__(self, data): self.data = data se [instruction] | Parse a given string to create a tree data structure. [input] | expr = "a + b * c"
[output] | def sort_words(words): return sorted(words) list_of_strings_sorted = sort_words(list_of_strings) print(list_of_strings_sorted) [instruction] | Create a Python program to sort of given list of strings in alphabetical order. [input] | list_of_strings = ["apple", "banana", "cherry", "dog"]
[output] | def get_even_numbers(numbers): even_numbers = [] for n in numbers: if n % 2 == 0: even_numbers.append(n) return even_numbers even_numbers = get_even_numbers(list_of_numbers) print(even_numbers) # prints [2, 4, 6] [instruction] | Write a Python program to create a new list which contains all even numbers from the given list. [input] | list_of_numbers = [1, 2, 3, 4, 5, 6]
[output] | def remove_val(numbers, val): result = [] for n in numbers: if n != val: result.append(n) return result list_without_2 = remove_val(list_of_numbers, value) print(list_without_2) # prints [1, 3, 4, 3] [instruction] | Create a Python function to remove all elements of the given list that are equal to the given value. [input] | list_of_numbers = [1, 2, 3, 4, 2, 3] value = 2
[output] | def permutations(nums): if len(nums) == 0: return [] if len(nums) == 1: return [[nums[0]]] perms = [] for i, n in enumerate(nums): sub_perms = permutations(nums[:i] + nums[i+1:]) for perm in sub_perms: perms.append([n] + perm) [instruction] | Make a Python program to generate all permutations of a given list. [input] |
[output] | def remove_whitespace(text): return text.replace(" ", "") text_without_whitespace = remove_whitespace(text) print(text_without_whitespace) # prints "Thisisasentencewithsomewhitespace!" [instruction] | Create a Python program to remove all whitespace from the given string. [input] | text = " This is a sentence with some whitespace! "
[output] | def remove_elements_at_indices(numbers, indices): for index in sorted(indices, reverse=True): del numbers[index] return numbers modified_list = remove_elements_at_indices(list_of_numbers, indices) print(modified_list) # prints [0, 1, 4] [instruction] | Make a Python program to delete elements from a given list at particular indices. [input] | list_of_numbers = [0, 1, 2, 3, 4, 5] indices = [2, 3, 5]
[output] | def bubble_sort(arr): for i in range(len(arr)): for j in range(0, len(arr)-i-1): if arr[j] < arr[j+1] : arr[j], arr[j+1] = arr[j+1], arr[j] array = [10, 5, 2, 7, 6] bubble_sort(array) print(array) # Output: [10, 7, 6, 5, 2] [instruction] | Sort an array of numbers in descending order using the bubble sort algorithm. [input] | `array = [10, 5, 2, 7, 6]`
[output] | In C++, a class is defined by using the keyword "class" followed by the class name followed by the body of the class, which is enclosed within a pair of curly braces. Within the body of the class are the class members, including the data members and member functions. For example, the following is h [instruction] | How do we define a class in C++? [input] |
[output] | query { posts { id title body author { name } } } [instruction] | Create a GraphQL query to get a list of all the posts in a blog. [input] |
[output] | Exception handling in Python is a process in which errors or exceptions in a program are handled using certain programming construct such as try-except or try-finally blocks so that the program can recover from such exceptions and continue running. Exception handling helps prevent critical errors in [instruction] | What is an exception handling code in Python? [input] |
[output] | def create_dictionary(list1, list2): if len(list1) != len(list2): return "lists have different lengths" else: my_dict = dict(zip(list1, list2)) return my_dict list1 = ['a', 'b', 'c'] list2 = [1, 2, 3] print(create_dictionary(list1, list2)) #output: {'a': 1, 'b': 2, ' [instruction] | Generate a code that creates a dictionary from two different lists with equal length. [input] | list1 = ['a', 'b', 'c'] list2 = [1, 2, 3]
[output] | a = 5 b = 3 if (a > b): print(True) else: print(False) [instruction] | Edit the following code to print true if the condition is met, false if not. [input] | a = 5 b = 3 if (a > b): print("true")
[output] | list1 = [1, 2, 3, 4, 5] print("First element:", list1[0]) print("Last element:", list1[-1]) for item in list1: print(item) #output: First element: 1 Last element: 5 1 2 3 4 5 [instruction] | Update the code to get 2 extra lines of output to print the first and last value of the list. [input] | list1 = [1, 2, 3, 4, 5]
[output] | list1 = [1, 2, 3, 4, 5] for item in list1: print(item) #output: 1 2 3 4 5 [instruction] | Add a loop to the following program so that it prints out each item in a list. [input] | list1 = [1, 2, 3, 4, 5]
[output] | struct employee { string name; int id; }; [instruction] | Declare a C++ structure that stores data about employees including their name and employee id. [input] |
[output] | <html> <head> <title>Example</title> </head> [instruction] | Fill in the missing characters in the given HTML code [input] | <htm__> <head> <tit__>Example</title> </he__>
[output] | let result = 0; [instruction] | Generate the syntax to declare a variable called 'result' as an integer in Javascript. [input] |