[output] | ^\d+$ [instruction] | Generate a regular expression to match a string which contains only digits. [input] |
[output] | #Use the given dictionary to find the value for the key "city" dictionary = {"name": "John Smith", "age": 42, "city": "Los Angeles"} city = dictionary["city"] print("The value for the key city is: " + city) [instruction] | Use the given dictionary to find the value for the key "city". [input] | {"name": "John Smith", "age": 42, "city": "Los Angeles"}
[output] | #Implement a function that takes in 2 strings and returns a new string consisting of alternating characters def alt_string(str1, str2): alt_str = "" length = len(str1) if len(str1) <= len(str2) else len(str2) for i in range(length): alt_str += str1[i] + str2[i] if [instruction] | Implement a function that takes in 2 strings and returns a new string consisting of alternating characters from the strings passed in. [input] | "hello" "world"
[output] | #Change the given code so that it prints the sentence "Hello, World!" print("Hello, World!") [instruction] | Change the given code so that it prints the sentence "Hello, World!" [input] | print("Goodbye, World!")
[output] | #Write a function that takes two parameters, a list and a number. def find_number(list_num, num): '''This function takes in a list of numbers and a number and returns the index of the number if it is found, else return -1.''' # Traverse through the list for i in range(len(list_num [instruction] | Write a function that takes two parameters, a list and a number. If a number is found in the list, the function should return its index, else it should return -1. [input] | [1, 2, 3, 4, 9], 2
[output] | #Summarize the given text in 3-5 sentences REST (Representational State Transfer) is an architecture style used to communicate between services over HTTP. It is composed of a set of constraints and properties that define how the services communicate and exchange data. REST is useful in implementing [instruction] | Summarize the given text in 3-5 sentences. [input] | REST is an architectural style that defines a set of constraints and properties based on HTTP. It basically uses HTTP for communication between services. It stands for Representational State Transfer, and defines the various ways by which services can provide data and be interacted with.
[output] | import requests from bs4 import BeautifulSoup url = 'url_of_webpage' page = requests.get(url) soup = BeautifulSoup(page.content, 'html.parser') text = soup.find_all(text=True) for t in text: print(t) [instruction] | Write a web scraping program to extract text from a given webpage [input] |
[output] | function fibonacci(n) { if (n == 0 || n == 1) { return n; } let fibo = [0, 1]; for (let i = 2; i <= n; i++) { let nextFibonacci = fibo[i - 1] + fibo[i - 2]; fibo.push(nextFibonacci); } return fibo[n]; } [instruction] | Create a JavaScript program to calculate the Fibonacci number for a given integer n [input] |
[output] | def hanoi(num_disks, from_peg, to_peg, aux_peg): if num_disks == 1: print("Move disk 1 from peg", from_peg,"to peg", to_peg) return hanoi(num_disks-1, from_peg, aux_peg, to_peg) print("Move disk",num_disks,"from peg",from_peg,"to peg",to_peg) hanoi(num_disks-1, aux_p [instruction] | Implement an algorithm to print the steps of the Tower of Hanoi problem. [input] |
[output] | def factorial(n): if n == 0: return 1 else : return n*factorial(n-1) [instruction] | Calculate the factorial of an integer using recursion. [input] |
[output] | int[] arr = new int[oldArray.length]; Arrays.fill(arr, 0); [instruction] | How do you create a new array of the same size as an existing array but with every element as 0 in Java? [input] |
[output] | def nested_list_doubled(original_list): new_list = [] for item in original_list: if isinstance(item, list): new_list.append(nested_list_doubled(item)) else: new_list.append(item) new_list.append(item) return new_list [instruction] | Write a function to create a new nested list with twice the length of the original. [input] | original_list = [1, 2, [3, 4], 5]
[output] | def in_order_traversal(tree): if tree != None: in_order_traversal(tree.left) print(tree.data,end=" ") in_order_traversal(tree.right) [instruction] | Write code to walk through a BST and print out all the elements in order. [input] |
[output] | def find_multiples(base, lower, upper): output = [] for i in range(lower, upper+1): if i % base == 0: output.append(i) return output [instruction] | Find all the multiples of a number in between two given numbers. [input] |
[output] | let series = []; for (let i = 10; i <= 41; i++) { series.push(i); } [instruction] | How do you generate a series of numbers from `10` to `41` in JavaScript? [input] |
[output] | public class Dog { public Dog() { } public void bark() { System.out.println("Woof!"); } } [instruction] | Create a Java class called "Dog" with a constructor and a bark() method that prints "Woof!". [input] |
[output] | CREATE TABLE my_database (id INTEGER PRIMARY KEY, name VARCHAR(255), size INTEGER); [instruction] | Create a database table with 3 columns: id, name and size. [input] |
[output] | function replaceNonAlphaNumCharacters(str) { let result = str.replace(/[^a-zA-Z0-9]/g, '#'); return result; } let str = "Hello* World!"; replaceNonAlphaNumCharacters(str); [instruction] | Write a function that takes a string and replaces all non-alphanumeric characters with the # symbol. [input] | let str = "Hello* World!"
[output] | public class SubstringFinder { public static List<String> findSubstrings(String str) { List<String> substrings = new ArrayList<>(); for (int i = 0; i < str.length(); i++) { for (int j = i + 1; j <= str.length(); j++) { String substr = str.substring(i [instruction] | Create a Java class to find all substrings of a given string. [input] | String str = "Hello World"
[output] | <?xml version="1.0" encoding="UTF-8"?> <html> <body> <h1>Hello, World!</h1> </body> </html> [instruction] | Convert this HTML code to its corresponding XML format [input] | <html> <body> <h1>Hello, World!</h1> </body> </html>
[output] | SELECT COUNT(*) FROM Employee [instruction] | Using a database query, count the number of employees in a company database. [input] |
[output] | <html> <head> <title>Time Display</title> <script> function updateTime() { let currTime = new Date(); document.getElementById("currentTime").innerHTML = currTime.toLocaleTimeString(); } </script> </head> <body onload="updateTime()"> [instruction] | Create a HTML page that displays the current time. [input] |
[output] | import json data = { "ratings": [ {"title": "Frozen II", "rating": 7.5}, {"title": "The Irishman", "rating": 8.2}, {"title": "Parasite", "rating": 8.5}, ] } data = json.loads(data) for item in data['ratings']: print("Rating for %s: %f" % (item['title'], item['r [instruction] | Parse this JSON data and print out the “rating” of every item in the list. [input] | { "ratings": [ {"title": "Frozen II", "rating": 7.5}, {"title": "The Irishman", "rating": 8.2}, {"title": "Parasite", "rating": 8.5}, ] }
[output] | SELECT SUM(price) FROM product [instruction] | Using an SQL query, sum up the total cost of all items in the product table. [input] |
[output] | let sum = a + b; console.log(sum); [instruction] | Find the sum of two numbers stored in two different variables in JavaScript. [input] | let a = 5; let b = 7;
[output] | public class SimpleCalculator { public SimpleCalculator() {} public double add(double a, double b) { return a + b; } public double subtract(double a, double b) { return a - b; } public double multiply(double a, double b) { return a * b; } p [instruction] | Create a class in Java that creates a simple calculator which will add, subtract, multiply, divide and take square root of two numbers. [input] |
[output] | let today= new Date(); let dd = String(today.getDate()).padStart(2, '0'); let mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0! let yyyy = today.getFullYear(); console.log(yyyy+mm+dd); [instruction] | Output the current date in YYYYMMDD format. [input] |
[output] | let my_array = [4, 5, 6]; let product = my_array.reduce((acc, cur) => acc * cur); [instruction] | Replace the commented out code with a single line of code that calcultes the product of all elements in the array. [input] | let my_array = [4, 5, 6]; // let product = 1; // for (let i = 0; i < my_array.length; i ++ ){ // product *= my_array[i]; // }
[output] | SELECT AVG(Age) FROM People WHERE City = {city} [instruction] | Create an SQL query to calculate the average age of people living in a given city. [input] | Table name: People Columns: Name, Age, City
[output] | let max_sum = 0; let current_sum = 0; for (let i=0; i < arr.length; i++) { current_sum += arr[i]; if (current_sum < 0) current_sum = 0; max_sum = Math.max(current_sum, max_sum); } console.log(max_sum); [instruction] | Determine the maximum sum of a subarray within the given array. [input] | [-2, 1, -3, 4, -1, 2, 1, -5, 4].