[output] | function findWords(str) { let words = []; let start = 0; for (let i = 0; i < str.length; i++) { if (str[i] == ' ') { let word = str.substring(start, i); if (word != '') words.push(word); start = i + 1; } } [instruction] | Write a JavaScript function to find all words in a string. [input] | This is a string
[output] | <input type="email" name="email" placeholder="Enter email address"> [instruction] | In HTML, write a code to create an input field to get an email address from a user. [input] |
[output] | SELECT COUNT(*) FROM employees WHERE age BETWEEN 30 AND 40; [instruction] | Create an SQL query to find the number of employees whose age is between 30 and 40 [input] |
[output] | const people = { "John": 30, "Emily": 28, "George": 25, "Karen": 33 } [instruction] | Create a JavaScript object with key-value pairs representing names and ages. [input] |
[output] | public abstract class Employee { private string employeeId; private string name; private string address; private string phoneNumber; private double salary; public string EmployeeId { get { return employeeId; } set { employeeId = value; } } publi [instruction] | Design an abstract employee class with following members. [input] |
[output] | Class properties make code more readable and shorter by allowing the user to access and set private variables without having to declare a public method for each. Additionally, class properties make it easy to control access rules for class variables, as you can create getters and setters for variabl [instruction] | Discuss the pros and cons of using class properties in C#. [input] |
[output] | class Node { public $item; public $parent; public $children; public function __construct($item, $parent = null) { $this->item = $item; $this->parent = $parent; $this->children = array(); } public function addChild($item) { $node = new Node($i [instruction] | Construct a 3 level hierarchical tree data structure in PHP. [input] |
[output] | function countNegatives(list) { let count = 0; for (let i=0; i<list.length; i++) { if (list[i] < 0) { count++; } } return count; } countNegatives([-2, -7, -11, 1, 4, 8, 10]); // returns 3 [instruction] | Find the number of negative numbers in a given list. [input] | List: [-2, -7, -11, 1, 4, 8, 10]
[output] | public void bubbleSort(int[] array) { int n = array.length; for (int i = 0; i < n-1; i++) { for (int j = 0; j < n-i-1; j++) { if (array[j] > array[j+1]) { int temp = array[j]; array[j] = array[j+1]; array[j+1] = temp; [instruction] | Write a function to perform buble sort. [input] |
[output] | <?php $query = "SELECT * FROM employees WHERE name LIKE '%john%'"; $result = mysqli_query($conn, $query); echo "<table>"; echo "<tr><th>ID</th><th>Name</th><th>Age</th></tr>"; while ($row = mysqli_fetch_assoc($result)) { echo "<tr><td>".$row['id']."</td><td>".$row['name']."</td><td>".$row['ag [instruction] | Display the results from a MySQL query in HTML table format. [input] | MySQL query: SELECT * FROM employees WHERE name LIKE '%john%'
[output] | words_starting_with_T = [word for word in words_list if word.startswith('T')] [instruction] | Using the given list, write a code to get a list of all the words starting with "T" [input] | words_list = ['Meteor', 'Timeline', 'Tablet', 'Timeframe', 'Trophy']
[output] | def parse_urls(url): queries = url.split('?')[1] queries_dict = {} for query in queries.split('&'): key, value = query.split('=') queries_dict[key] = value return queries_dict [instruction] | Create a function named "parse_urls" which takes a single string parameter and returns a dictionary of queries from the URL. [input] | url="https://www.example.com/product?color=red&size=small"
[output] | class Car: def __init__(self, make, model, year): self.make = make self.model = model self.year = year [instruction] | Create a class named "Car" to store information about a car's make, model and year. [input] |
[output] | def remove_vowels(strings): vowels = ['a', 'e', 'i', 'o', 'u'] new_strings = [] for string in strings: new_strings.append(''.join([char for char in string if char.lower() not in vowels])) return new_strings [instruction] | Using the list of strings, create a new list without any vowels. [input] | strings = ['apple', 'ball', 'cat']
[output] | The algorithm used for sorting the given array of 16 elements is Quick Sort. [instruction] | Identify the algorithm used for sorting a given array of 16 elements. [input] | [12, 4, 15, 7, 8, 10, 1, 11, 13, 14, 3, 6, 5, 2, 9, 16]
[output] | import java.util.ArrayList; import java.util.List; public class ScheduleGenerator { public static void main(String[] args) { List<Integer> ids = new ArrayList<Integer>(); ids.add(1); ids.add(2); ids.add(3); System.out.println(generateSchedule(ids)); } public static Lis [instruction] | Write a Java program to generate a schedule for students with a given set of available IDs. [input] | IDs to be scheduled [1, 2, 3]
[output] | import pandas as pd import matplotlib.pyplot as plt # Read the dataset df = pd.read_csv('data.csv') # Create visualization fig, ax = plt.subplots(figsize=(10,8)) ax.bar(df['State'], df['Cases'], color='#88e398') plt.xlabel('States') plt.ylabel('Coronavirus Cases') plt.title('Covid-19 Cases per U [instruction] | Create a data visualization in Python using the given dataset. [input] | Dataset: The data contains information about the latest coronavirus cases per US state
[output] | import pandas as pd from sklearn.model_selection import train_test_split from sklearn.linear_model import LinearRegression # Read the dataset data = pd.read_csv("data.csv") # Split the data into features and labels X = data.drop(['result'], axis=1) y = data['result'] # Split the data into train a [instruction] | Train a machine learning algorithm from a given dataset. [input] | Dataset: The data contains information about students' results in an exam.
[output] | public class Hovercar { // Properties private String color; private int maxSpeed; private int currentSpeed; // Constructor public Hovercar(String color, int maxSpeed) { this.color = color; this.maxSpeed = maxSpeed; this.currentSpeed = 0; } // Getters and Setters p [instruction] | Create a Java class to represent a new type of vehicle called hovercar. [input] |
[output] | Encrypted string: "Khoor Zruog" [instruction] | Encrypt a given string using a Caesar cipher. [input] | String: "Hello World"
[output] | @interface MyAnnotation { String author() default "unknown"; int date(); } [instruction] | Define a Java annotation for a class. [input] |
[output] | .hidden { display: none; } [instruction] | Write a CSS rule to hide all elements with class "hidden". [input] |
[output] | function sumArrayElements(arr) { let sum = 0; for (let i = 0; i < arr.length; i++) { sum += arr[i]; } return sum; } [instruction] | Create a Javascript function to take an array of numbers and return the sum of all its elements. [input] | [1, 2, 3, 4, 5]
[output] | p { font-size: 16px; } [instruction] | Write a CSS rule to make all p elements have a font size of 16px. [input] |
[output] | import java.util.Scanner; public class Factorial { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter a number: "); int n = sc.nextInt(); int factorial = 1; for (int i = 1; i <= n; i++) { factorial = factorial * i; } System.out. [instruction] | Create a Java program to take an integer input from the user and print its factorial. [input] |
[output] | Objects are instantiated in Python by using the keyword "class". Python then creates a new instance of the class and assigns it a unique object ID. This object is then used as the basis for the object's other attributes and methods, which are defined within the class definition. Object instantiation [instruction] | How are objects instantiated in Python? [input] |
[output] | A join operation in a relational database is used to combine data from two or more tables based on a common field. This is done to match and retrieve related data from one or multiple tables and then use it as a single result. The most common type of join is an inner join, which combines only the ma [instruction] | What is the purpose of a join operation in a relational database? [input] |
[output] | Dictionaries in Python are implemented as hash tables. Each key-value pair is stored as an entry in the hash table, and a hash function is used to map the key to its corresponding index in the table. This allows fast lookups of the associated value of a given key and makes dictionary operations such [instruction] | How are dictionaries implemented in Python? [input] |
[output] | <?php $sum = 0; for ($i = 0; $i <= 50; $i+=2) { $sum += $i; } echo "The sum of all even numbers from 0 to 50 is $sum"; ?> [instruction] | Implement a PHP program to find the sum of all even numbers between 0 and 50. [input] |
[output] | In Java, an immutable object is an object whose state cannot be modified once it is created. An immutable object's state can still be accessed, but its properties cannot be changed. Mutable objects, on the other hand, can be modified after they are created. This is accomplished by providing methods [instruction] | How is an immutable object different from a mutable object in Java? [input] |