[output] | CREATE TRIGGER tr_storeTime BEFORE INSERT OR UPDATE ON <Table> FOR EACH ROW BEGIN IF INSERTING THEN SET NEW.addedTime = NOW(); END IF; IF UPDATING THEN SET NEW.updatedTime = NOW(); END IF; END; [instruction] | Create a MySQL trigger to store the times for insertion and updating a row in a table. [input] |
[output] | onSubmit() { this.form.reset(); } [instruction] | Reset the input field in areact Native form after submitting the form. [input] |
[output] | def print_range(start, end): for value in range(start + 1, end): print(value, end = " ") [instruction] | Create a function in python to print all values between two given values. Do not include the two given values in the output. [input] |
[output] | function maxNum(num1, num2) { if (num1 > num2) { return num1; } else { return num2; } } [instruction] | Create a function in JavaScript that finds the maximum number between two given numbers. [input] |
[output] | <form method="post" action="verify.php"> Enter your email address:<br> <input type="text" name="email"> <br><br> <input type="submit" value="Verify"> </form> [instruction] | Create an HTML page with a form that verifies if the email address entered is valid or not. [input] |
[output] | button { border: 2px solid transparent; } [instruction] | Write a CSS rule to set a transparent border for all buttons on a page. [input] |
[output] | <!DOCTYPE html> <html> <head> <title>Example Document</title> </head> <body> <h1>Heading</h1> <p>Hello, World!</p> </body> </html> [instruction] | Create an HTML document with a heading "Heading" and a paragraph with the text "Hello, World!" [input] |
[output] | import random numbers = [] for i in range(15): numbers.append(random.randrange(0, 10)) print(numbers) [instruction] | Insert 15 random numbers between 0 and 10 in a list. [input] |
[output] | function lengths(words) { var length = []; for (var i = 0; i < words.length; i++) { length.push(words[i].length); } return length; } [instruction] | Write a JavaScript function that takes an array of words and returns an array of the lengths of each of those words. [input] |
[output] | import re def parse(expression, string): matches = re.finditer(expression, string) return [match.group(0) for match in matches] [instruction] | Write a Python program to parse a text string given a regular expression and return the matches. [input] |
[output] | import tensorflow as tf # Define the model model = tf.keras.Sequential([ tf.keras.layers.Flatten(input_shape=(28, 28)), tf.keras.layers.Dense(128, activation='relu'), tf.keras.layers.Dropout(0.2), tf.keras.layers.Dense(4, activation='softmax') ]) # Compile the model model.compile(o [instruction] | Create a TensorFlow neural network model to classify animals into 4 categories. [input] |
[output] | db.collection.find({Company: { $regex: /Apple/ }}); [instruction] | Create a MongoDB query to find all the documents containing the string "Apple" in the field "Company". [input] |
[output] | When a web server receives a request, it typically passes the request to a request handler. The request handler interprets the request and takes the appropriate action. Depending on the type of request, this could include accessing a file or a database, or running an application. After the request h [instruction] | Describe how a web server handles a request. [input] |
[output] | def share(message): import facebook graph = facebook.GraphAPI(access_token=<ACCESS_TOKEN>) graph.put_object(parent_object='me', connection_name='feed', message=message) [instruction] | Edit the following code to add a sharing feature that posts to Facebook. [input] | def share(message): #code here
[output] | The "static" keyword in Java is used to define static members of a class. This includes static methods, static variables, static blocks, and static inner classes. Static methods can be invoked without creating an instance of the class, and static variables are shared among all objects of the same cl [instruction] | What does the “static” keyword do in Java? [input] |
[output] | class Student: def __init__(self, name, email, age, degree_type): self.name = name self.email = email self.age = age self.degree_type = degree_type [instruction] | Create a class that represents a student that contains the following information: name, email, age and type of degree. [input] |
[output] | def print_divisors(x): divisors = [] for i in range(1, x + 1): if(x % i == 0): divisors.append(i) print(divisors) [instruction] | Create a program that takes in a numeric value, X, and prints all the positive divisors of that number. [input] | X = 8
[output] | def is_prime(num): for n in range(2, num): if(num % n == 0): return False else: return True [instruction] | Create a function that takes in an integer and returns true if the number is prime or false if the number is not prime. [input] |
[output] | def get_average_sum(arr): total = 0 count = 0 for sub_arr in arr: total += sum(sub_arr) count += len(sub_arr) return total / count [instruction] | Create a function that takes an array of numbers, calculates the sum of the numbers across all the arrays, and returns the average of those sums. [input] | arr = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
[output] | Stochastic Gradient Descent optimization algorithm is used in the given snippet of code. [instruction] | What type of optimization algorithm is used in the following snippet of code? [input] | weights = np.random.rand(2, 1) for epoch in range(50): predictions = predict(x, weights) gradients = calcluate_gradients(x, predictions, y) weights -= gradients * learning_rate
[output] | def longest_substring(input_string): longest_substring = "" for i in range(len(input_string)): current_substring = "" for j in range(i, len(input_string)): if input_string[j] not in current_substring: current_substring += input_string[j] [instruction] | Rewrite the following code to use loop instead of recursion. [input] | def longest_substring(input_string): if len(input_string) <= 1: return input_string else: first_letter = input_string[0] rest_substring = input_string[1:] sub_string = longest_substring(rest_substring) if first_letter in sub_string: return
[output] | def print_pattern(n): for i in range(1, n+1): print("*" * i) print_pattern(4) [instruction] | Write a function which will print out a given pattern. [input] | * ** *** ****
[output] | class ArithmeticOperator: def __init__(self, operator, left, right): self.operator = operator self.left = left self.right = right def operate(self): if self.operator == "+": return self.left + self.right elif self.operator == "-": [instruction] | Write a class that implements an arithmetic operator. [input] | None
[output] | def print_fibonacci_series(n): a = 0 b = 1 print(a, end = " ") print(b, end = " ") for _ in range(2, n): c = a + b a = b b = c print(c, end = " ") print() print_fibonacci_series(5) [instruction] | Print out the Fibonacci series up to a given number. [input] | n = 5
[output] | The output of the following code is 3. [instruction] | Given the following code, find the output. [input] | def f(x): if x == 0 or x == 1: return 1 return f(x-1) + f(x-2) print(f(4))
[output] | def rod_cutting(arr, n): dp = [-1 for _ in range(n+1)] dp[0] = 0 for i in range(1, n+1): for j in range(i): dp[i] = max(dp[i], arr[j] + dp[i - j - 1]) return dp[n] [instruction] | Edit the given code to use dynamic programming to solve the problem. [input] | def rod_cutting(arr, n): if n <= 0: return 0 max_val = 0 for i in range(0, n): max_val = max(max_val, arr[i] + rod_cutting(arr, n-i-1)) return max_val
[output] | import random # generate random integers int_list = [random.randint(0, 10) for i in range(10)] # calculate the sum total = 0 for e in int_list: total += e # print the sum print(total) [instruction] | Create an array of random integers from 0-10 and print the sum of all elements in the array. [input] |
[output] | from flask import Flask app = Flask(__name__) @app.route('/') def hello(): return "<h1>Hello, World!</h1>" if __name__ == '__main__': app.run() [instruction] | Create a Flask application to display a web page containing the words "Hello, World." [input] |
[output] | def reverse_string(string): return string[::-1] string_input = 'I love coding' reverse_string(string_input) [instruction] | Use Python to reverse the order of a string input. [input] | I love coding
[output] | public class MyClass { private String name; // constructor public MyClass(String name) { this.name = name; } // getName public String getName() { return this.name; } // setName public void setName(String name) { this.name = name; } // displa [instruction] | Create a Java class named "MyClass" with three methods - getName(), setName(), and displayName(). [input] |