[output] | def frequency_count(word): # dictionary to store the frequency of occurrence frequency = {} # iterate through each character for char in word: # if the character is present in the frequency dictionary if char in frequency: # increase the count of the char [instruction] | Calculate the frequency of occurrence of each letter in a word. [input] | word = "programming"
[output] | class Person { constructor(firstName, lastName) { this.firstName = firstName; this.lastName = lastName; } } [instruction] | Create an object-oriented JavaScript class for a Person that stores a first and last name. [input] |
[output] | import tensorflow as tf import numpy as np # Hyperparameters n_inputs = 784 # MNIST n_hidden1 = 512 n_hidden2 = 256 n_outputs = 10 # Build a model X = tf.placeholder(tf.float32, shape=(None, n_inputs), name="X") y = tf.placeholder(tf.int64, shape=(None), name="y") with tf.name_scope("dnn"): [instruction] | Use TensorFlow to build a multi-layer perceptron to classify the MNIST digits. [input] |
[output] | <!DOCTYPE html> <html> <head> <title>3 Column Layout</title> <style> body { width: 1000px; margin: 0 auto; } .column-left { float: left; width: 33%; } .column-center { float: left; width: 33%; } .column-right { float: left; [instruction] | Use HTML and CSS to format a page with three columns, two of which contain two paragraphs each and the last containing a list of 10 items. [input] |
[output] | /(\S+)@(\S+)/ [instruction] | Using Perl, use a regular expression to search for any email addresses in a given line of text. [input] | Please contact info@example.com for more information.
[output] | this.addEventListener("mouseover", function() { this.style.cursor = "pointer"; }); [instruction] | Put the following JavaScript snippet into Standard Form. [input] | onMouseOver="this.style.cursor='pointer'"
[output] | function parseJSONString(jsonString) { return JSON.parse(jsonString); } [instruction] | Using Node.js, create a function to take a JSON string and return a JavaScript object. [input] |
[output] | entries = db.execute_query("SELECT * FROM users ORDER BY id DESC LIMIT 30") [instruction] | Edit the given code to limit the output to only the 30 most recent entries in the database. [input] | entries = db.execute_query("SELECT * FROM users")
[output] | The locality for Pin Code 400615 is Vashi, Navi Mumbai, Maharashtra. [instruction] | Find the Locality from an Indian Pin Code. [input] | Pin Code: 400615
[output] | my_array = [23, 60, 12, 44, 97, 72, 4, 39, 66, 84] [instruction] | Make an array with 10 integers between 0 and 100. [input] |
[output] | The GCD of numbers 8 and 12 is 4. [instruction] | Calculate the GCD of numbers 8 and 12. [input] |
[output] | def list_to_dict(lst): my_dict = {} for i in lst: my_dict[str(i)] = [i] return my_dict if __name__ == '__main__': my_list = [1, 2, 3, 4] print(list_to_dict(my_list)) [instruction] | Write a function to convert the given list of integers into a dictionary of lists. [input] | my_list = [1, 2, 3, 4]
[output] | import random def generate_random_matrix(rows, cols): matrix = [] for i in range(rows): matrix.append([]) for j in range(cols): matrix[i].append(random.randint(0, 9)) return matrix if __name__ == '__main__': rows = 4 cols = 4 print(generate_rando [instruction] | Create a 4x4 matrix filled with random numbers between 0 and 9. [input] |
[output] | def sum_even_numbers(n): '''This function will calculate the sum of all even numbers in the given range.''' total = 0 for i in range(n): if i%2==0: total += i return total [instruction] | Amend the following Python function to calculate the sum of all even numbers in the given range. [input] | def sum_even_numbers(n): '''This function will calculate the sum of all numbers in the given range.''' total = 0 for i in range(n): total += i return total
[output] | class Book(): def __init__(self, name, author): self.name = name self.author = author def printTitle(self): print("The book title is: "+ self.name) [instruction] | Add a method called "printTitle" to the “Book” class defined above. [input] |
[output] | def print_score(score): try: score = int(score) print(f'The score is {score}') except ValueError: print("The score must be an integer.") [instruction] | Amend the following Python code to add error handling to the function print_score. [input] | def print_score(score): print(f'The score is {score}')
[output] | def compound_interest(P, r, n): return P * (1 + (r/n))**(n*t) [instruction] | Create a function to calculate the compound interest rate given the initial principal amount P, the annual interest rate r and the number of times compounding occurs in a year n. [input] |
[output] | class List: def __init__(self, data): self.data = data def isEmpty(self): return not self.data [instruction] | Add a method called “isEmpty” to the following Python class to check if the list is empty or not. [input] | class List: def __init__(self, data): self.data = data
[output] | [2, 3, 4, 5, 1] [instruction] | Move the element of the list at index 0 to the end of the list. [input] | [1, 2, 3, 4, 5]
[output] | def min_max(data): min_value = min(data) max_value = max(data) return min_value, max_value [instruction] | Write a Python function to find the maximum and minimum numbers from a sequence of numbers. [input] |
[output] | Dynamic programming is a way of solving problems by breaking them down into a collection of smaller subproblems. It works by storing solutions to subproblems so that each subproblem is only solved once. This allows for faster computation and efficient memory usage, as solutions are stored and reused [instruction] | How does dynamic programming work? [input] |
[output] | db.collection.find({city: "New York"}) [instruction] | Construct a query using MongoDB to find all the documents with a "city" field that equals "New York". [input] |
[output] | The command to find out the amount of RAM installed in a Linux system is "free -m". [instruction] | What command can you use in a Linux terminal to find out the amount of RAM installed on your system? [input] |
[output] | SELECT * FROM table_name WHERE user_id = 3; [instruction] | Write a SQL query to find rows that contain the field "user_id" with a value of 3. [input] |
[output] | SELECT SUM(num) FROM table_name [instruction] | Create a SQL query that returns the sum of all the numbers in the "num" column. [input] |
[output] | db.collection.find({user_id: {$gt: 5}}) [instruction] | Construct a query using MongoDB to find documents where the "user_id" field contains any number greater than 5. [input] |
[output] | SELECT TableA.id, TableA.name, TableB.age FROM TableA INNER JOIN TableB ON TableA.id = TableB.id; [instruction] | Write an SQL query to join two tables using an inner join. [input] | TableA id | name 1 | Joe 2 | Juan TableB id | age 1 | 25 2 | 30
[output] | #!/bin/bash curr_hour=$(date +'%H') if [ $curr_hour -ge 20 -o $curr_hour -lt 8 ] then echo "It's nighttime" fi [instruction] | Write a Bash script to print a message when the system time is between 8pm and 8am. [input] |
[output] | function convertToFahrenheit(celsius) { return (celsius * 1.8) + 32; } function convertToCelsius(fahrenheit) { return (fahrenheit - 32) / 1.8; } [instruction] | Write a JavaScript program to convert temperatures to and from Celsius, Fahrenheit. [input] |
[output] | def calculate_volume(shape, side): if shape == "cube": return side ** 3 [instruction] | Create a function to calculate the volume of the given 3D shape. [input] | type: "cube" side: 6