[output] | Java is a compiled language while JavaScript is interpreted. Java is a class-based language while JavaScript is a prototype-based language. Java is statically typed while JavaScript is dynamically typed. Java supports method overloading while JavaScript does not. [instruction] | Identify the differences between Java and JavaScript languages. [input] |
[output] | A linear data structure of linked nodes. [instruction] | Describe what is a linked list data structure in 10 words or less. [input] |
[output] | public class Fibonacci { public static void printFibonacci(int n) { int n1 = 0, n2 = 1; for (int i = 0; i < n; i++) { System.out.print(n1 + " "); int sum = n1 + n2; n1 = n2; n2 = sum; } } } [instruction] | Develop a function to print out the Fibonacci sequence in Java. [input] |
[output] | function reverseArray (arr) { return arr.reverse(); } reverseArray([1, 2, 3]); // => [3, 2, 1] [instruction] | Develop a JavaScript function to reverse an array. [input] | [1, 2, 3]
[output] | SELECT * FROM table_name; [instruction] | Develop an SQL query to select all rows from a table that has two columns: 'name' and 'age'. [input] |
[output] | Function is a language construct used to define a reusable instruction block, typically with parameters and a return value. [instruction] | Classify the term "function" as a programming language feature. [input] |
[output] | for number in range(1, 11): print(number) [instruction] | Create a Python program that prints all numbers in the range 1-10. [input] |
[output] | double x = 25; double y = 4; double result = Math.Round(x/y); [instruction] | Edit the following C# code to round the result of x divided by y to the nearest integer. [input] | double x = 25; double y = 4; double result = x/y;
[output] | import requests from bs4 import BeautifulSoup url = 'https://en.wikipedia.org/wiki/Web_scraping' page = requests.get(url) soup = BeautifulSoup(page.text, 'html.parser') links = [link.get('href') for link in soup.find_all('a') if 'http' in link.get('href')] print(links) [instruction] | Write a web scraper in Python to get all the external links from a webpage. [input] | url = 'https://en.wikipedia.org/wiki/Web_scraping'
[output] | even_nums = [] for num in range(0, 21): if num % 2 == 0: even_nums.append(num) print(even_nums) [instruction] | Output an array of even numbers from 0 to 20 using a for loop in Python. [input] |
[output] | import json data = '{"name": "John Doe", "age": 25}' data = json.loads(data) print(data["name"]) [instruction] | Create a Python script to parse a JSON string and print the value corresponding to the key 'name'. [input] | {"name": "John Doe", "age": 25}
[output] | def insert_item(lst, index, item): lst.insert(index, item) return lst [instruction] | Write a code to insert a new item into a given list at the specified index. [input] | [1, 2, 3, 4], 0, 10
[output] | import langdetect def detect_language(text): language = langdetect.detect(text) return language [instruction] | Write a code to recognize the most likely language of a given text. [input] |
[output] | def generate_seq(k, n): seq = [] for i in range(k, n+1): seq.append(i) return seq [instruction] | Create a program to generate a sequence of integers that starts at k and ends at n in the following format: [k, k+1, ..., n-1, n] [input] |
[output] | def print_letters(string): for letter in string: print(letter) [instruction] | Formulate a solution to print out each letter of a string individually. [input] |
[output] | import copy def clone_dict(dict): return copy.deepcopy(dict) [instruction] | Generate a code snippet to clone/copy a dictionary. [input] |
[output] | def prime_factors(num): factors = [] i = 2 while num > 1: if num % i == 0: factors.append(i) num = num // i else: i += 1 return factors [instruction] | Suggest a solution to print the prime factorization of a number. [input] |
[output] | def reverse_in_place(arr): n = len(arr) for i in range(n//2): arr[i], arr[n-i-1] = arr[n-i-1], arr[i] [instruction] | Create a program to reverse an array in place, i.e. without creating a copy. [input] |
[output] | List comprehension - a data structure that uses a single expression to generate a list of elements. [instruction] | Classify this short programming code into its data structure category. [input] | h = [x for x in range(2, 101, 2)]
[output] | def max_list(lst): max = None for x in lst: if max is None or x > max: max = x return max [instruction] | Modify the following function to return the maximum value in a list. [input] | def max_list(lst): max = 0 for x in lst: max = x return max
[output] | def combinations(arr) arr.length.times do |i| arr.length.times do |j| if i != j print arr[i], arr[j] end end end end combinations(['a', 'b', 'c']) [instruction] | Generate a correct Ruby program to print all possible combinations of a given list. [input] | ["a", "b", "c"]
[output] | def num_to_str(num): return str(num) [instruction] | Write a python script to convert a given number to a string. [input] | num = 1234
[output] | try: num = int(input("Enter a number: ")) print (num) except Exception as e: print(str(e)) [instruction] | Edit the following code to capture the errors and print them. [input] | try: num = int(input("Enter a number: ")) print (num) except: pass
[output] | for i in range(len(lst)): lst[i] *= 2 [instruction] | Write a code to update the elements of a list inplace. [input] | lst = [2, 4, 6, 8]
[output] | print(str(num).rstrip('0').rstrip('.')) [instruction] | Delete all the trailing zeros of a given float number. [input] | num = 18.1000
[output] | newArr = arr.reverse() console.log(newArr) [instruction] | Write a JavaScript code to list each item of a given array into a new array in reverse order. [input] | arr = [1, 2, 3, 4, 5]
[output] | import bs4 html = "<html><h1>Heading 1</h1><h2>Heading 2</h2><h2>Heading 3</h2></html>" soup = bs4.BeautifulSoup(html, 'html.parser') h2_list = soup.find_all('h2') print(h2_list) [instruction] | Read an HTML page and extract all the <h2> tags. [input] | <html><h1>Heading 1</h1><h2>Heading 2</h2><h2>Heading 3</h2></html>
[output] | for (let i = 0; i < 2; i++) { sayHello(); } [instruction] | Fill in the blanks to write a code in JavaScript that calls a function two times. [input] | function sayHello() { console.log('Hello'); }
[output] | function rotateLeft(arr, pos) { for (let i = 0; i < pos; i++) { var remove = arr.shift(); arr.push(remove); } return arr; } console.log(rotateLeft(arr, pos)); [instruction] | Write a JavaScript code to rotate an array by n position to the left. [input] | arr = [1, 2, 3, 4, 5] pos = 2
[output] | sum_value = sum(2, 6) [instruction] | Using the function above, complete the following statement to compute the sum from 2 to 6. [input] |