[output] | g++ -o example example.cpp [instruction] | Compile the example program that prints "Hello, World!" in C++. [input] |
[output] | SELECT table_name FROM information_schema.tables WHERE table_schema NOT IN ('pg_catalog', 'information_schema'); [instruction] | List all the table names in a PostgreSQL database. [input] |
[output] | SELECT email FROM users WHERE email LIKE 'p%'; [instruction] | Select the email addresses the start with the letter "p" from the table "users". [input] |
[output] | function parseQueryString(query) { let components = query.split("&"); let data = {}; for (let c of components) { let pair = c.split("="); data[pair[0]] = pair[1]; } return data; } console.log(parseQueryString(query)); // {name: 'John', age: '30'} [instruction] | Write a function to parse a query string into its components in JavaScript. [input] | query = "name=John&age=30"
[output] | String name = "John"; [instruction] | Create a variable and assign a value to it in Java. [input] |
[output] | [2, 4, 6, 8, 10] [instruction] | Create a list containing the even numbers from #1 to #10. [input] |
[output] | def my_function(x, y, z): a = x + 5*y - z [instruction] | Edit the error in this code. [input] | def my_function(x, y, z): a = x + 5y - z
[output] | <html> <head> <style> div { width: 100px; height: 100px; border-radius: 50%; } #circle1 { background-color: red; } #circle2 { background-color: green; width: 80px; height: 80px; } #circle3 { background- [instruction] | Create a web page with HTML/CSS that consists of three circles of different colors and different sizes. [input] |
[output] | my_list = [1, 2, 3, 2, 3, 4, 5] duplicated_nums = [] for i in my_list: if my_list.count(i) > 1: duplicated_nums.append(i) print(list(set(duplicated_nums))) # The output will be [2, 3] [instruction] | Create a script that prints the duplicate elements from a given list of numbers. [input] | my_list = [1, 2, 3, 2, 3, 4, 5]
[output] | my_list = ["apple", "banana", "orange"] my_list = list(map(str, my_list)) # The output will be['apple', 'banana', 'orange'] [instruction] | Change this list of words into a list of strings. [input] | my_list = ["apple", "banana", "orange"]
[output] | 2550 # The output will be 2550 [instruction] | What is the sum of all the even numbers in the range 1-100 inclusive? [input] |
[output] | let number = Number(prompt("Enter a number:")); let sum = 0; while (number > 0) { let last_digit = number % 10; sum = sum + last_digit**3; number = (number - last_digit)/10; } console.log(sum); # The output will be the sum of the cube of the digits [instruction] | Write a JavaScript program that asks the user to enter a number and then prints the sum of the cube of the digits of the number. [input] |
[output] | <html> <head> </head> <body> Hello world. </body> </html> [instruction] | Generate an HTML page on the browser with the text "Hello world." [input] |
[output] | The Big O notation for a linear search is O(n), where n is the number of elements in the given list. [instruction] | What is the Big O notation for a linear search? [input] |
[output] | def serialize(root): if not root: return "None" serializedTree = root.val serializedTree += "," + serialize(root.left) serializedTree += "," + serialize(root.right) return serializedTree def deserialize(serializedTree): q = deque(serializedTree.split(',')) [instruction] | Given a binary tree, write a function to serialize and deserialize the tree. [input] |
[output] | The prerequisites for learning Python are basic knowledge of Computer Science concepts, knowledge of some programming language like C/C++, understanding of Object-Oriented Programming, and familiarity with some text editors like Notepad++, Visual Studio Code, etc. [instruction] | What are the prerequisites for learning Python? [input] |
[output] | def char_frequency(string): counts = {} for char in string: if counts.get(char) == None: counts[char] = 1 else: counts[char] += 1 return counts [instruction] | Create a function which takes in a string and returns a dictionary that counts its character frequency. [input] |
[output] | One way to flatten a two dimensional list is to use the itertools.chain() method. This method takes an iterable of iterables and returns a single iterable that contains all the elements of the original iterables. [instruction] | How would you flatten a two dimensional list? [input] |
[output] | Function scope is important in Python because it allows for the scoping of data to the specific environment in which the function was invoked. This is critical for ensuring that code runs correctly and that variables are isolated to the environment in which the associated function was called. Scopin [instruction] | Explain why function scope is important in Python. [input] |
[output] | The most efficient way to search for an element in a list is by using a binary search, which is a divide and conquer search algorithm that halves the search space after each iteration. Binary search is generally more efficient than linear search, as it has a time complexity of O(log n). [instruction] | What is the most efficient way to search for an element in a list? [input] |
[output] | To print the element at the index 5 in an array, you need to use the index accessor brackets, passing the index of the element that needs to be printed as an argument. For example, if the array is named `arr`, you can print the element at index 5 by writing `cout << arr[5]`;. [instruction] | What do you need to do to print the element at the index 5 in an array? [input] |
[output] | A doubly-linked list is a data structure that allows efficient insertion and deletion of elements at the beginning, middle and end. It consists of nodes, which contain data and two references (or links) each pointing to the previous and/or next node in the linked list. By traversing the list via the [instruction] | Name a data structure that allows efficient insertion and deletion of elements at the beginning, middle and end. [input] |
[output] | A mathematical function can be represented in programming by defining a function that takes in relevant inputs and returns the output of the mathematical function. For example, the Pythagorean theorem can be represented by a function that takes two parameters, the length of the two sides of a right [instruction] | How can a mathematical function be represented in programming? [input] |
[output] | The effect of calling the given JavaScript function on the list provided is that the list is re-arranged in ascending order. The sort() function sorts the elements in the list in ascending order according to each element's position relative to other elements in the list. The function has been provid [instruction] | Explain the effect of calling the following JavaScript function on the list provided. [input] | list = [4,8,2,7]; function sort_ascending(list) { list.sort(function(a, b){return a-b}); }
[output] | The reduce() method can be used to find the maximum element in an array by applying a function to each element of the array that checks if the current element is greater than the previously seen maximum. This function can be used as the argument to the reduce() method and it will return the maximum [instruction] | How can you find the maximum element in an array using the reduce() method? [input] |
[output] | The function in Python which can be used to convert a list to a dictionary is the dict() function. This function takes in an iterable such as a list as an argument and returns a dictionary with the elements of the iterable as the keys and their index as the values. [instruction] | Name a function in Python which can be used to convert a list to a dictionary. [input] |
[output] | public class Circle { private double radius; private double area; public Circle(double radius) { this.radius = radius; this.area = Math.PI * Math.pow(this.radius, 2); } public double getRadius() { return this.radius; } public double getArea() { return this.area; } } [instruction] | Create a Java class that defines a circle with two double data fields, radius and area. [input] |
[output] | import django from django.contrib.auth.models import User, Group from django.contrib import admin from rest_framework import viewsets, routers from myapp.models import MyModel class MyModelViewSet(viewsets.ModelViewSet): queryset = MyModel.objects.all().filter(is_active=True) serializer_cla [instruction] | Create an API using Django Rest Framework to retrieve data from a PostgreSQL database table. [input] |
[output] | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>My Page</title> </head> <body> <p>The result of addTwoNumbers(1,2) is <span id="result"></span></p> <script> function addTwoNumbers(a,b){ return a+b; } var result = addTwoNumbers(1,2); document.getElementById("result").in [instruction] | Create a web page that prints out the return value of the following function call in the browser. [input] | function addTwoNumbers(a,b){ return a+b; }
[output] | def copy_list(lst): new_lst = lst[:] return new_lst my_list = [1, 2, 3, 4] print(copy_list(my_list)) [instruction] | Implement a function in Python that makes a copy of a list. [input] | my_list = [1, 2, 3, 4]