[output] | class Circle(): def __init__(self, radius): self.radius = radius [instruction] | Create a class in Python named 'Circle' with a parameterized constructor to take the radius of the circle as input. [input] |
[output] | SELECT name FROM employees WHERE id = ? [instruction] | Write an SQL query to retrieve the employee’s name from a table with the employee’s id. [input] | employees (id, name, age)
[output] | { "key1": "value1", "key2": "value2" } [instruction] | Create a JSON string that represents a dictionary of two key-value pairs. [input] |
[output] | <p>This is a paragraph</p> [instruction] | Write HTML to create a paragraph with the text "This is a paragraph". [input] |
[output] | /\S+@\S+\.com$/ [instruction] | Construct a regular expression that matches an email address that ends in .com. [input] |
[output] | list_of_lists = [[1,2,3], [4,5,6], [7,8,9]] [instruction] | Convert the following matrix into a list of lists in Python. [input] | [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
[output] | let randomNumber = Int.random(in: 0..<10) [instruction] | Using Swift, generate a random integer between 0 and 10. [input] |
[output] | @array = ("one","two","three","four"); # remove the last element pop(@array); # print the resulting array print "@array\n"; [instruction] | Write a Perl program to remove the last element from an array and return the resulting array. [input] |
[output] | #include <stdlib.h> #include <time.h> float genRandomNum(){ srand (time(NULL)); float randomNum = (float)rand()/(float)(RAND_MAX); return randomNum; } [instruction] | Create a function in C++ that generates a random number between 0 and 1. [input] |
[output] | #include <stdio.h> int isInteger(int x) { // Your code here if(x == (int) x) return 1; else return 0; } int main() { int num; printf("Enter a number: "); scanf("%d", &num); if(isInteger(num)){ printf("It is an integer number."); [instruction] | Implement a C program which will check if user input is an integer number or not. [input] |
[output] | SELECT COUNT(*) FROM customers WHERE salary > 40000; [instruction] | Write a SELECT statement in SQL to get the count of customers with a salary greater than 40,000. [input] |
[output] | #!/bin/bash #Program to Retrieve System Information memory=$(free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }') #Storage Information storage=$(df -h | awk '$NF=="/"{printf "Disk Usage: %d/%dGB (%s)\n", $3,$2,$5}') #IP Address ipaddress=$(ip addr | awk '/^[0-9]+: / [instruction] | Write a Bash script which will retrieve system information, including memory, storage and IP address. [input] |
[output] | calculate median <- function(arr){ sorted <- sort(arr) n <- length(arr) if(n%%2 == 0){ mid <- n/2 median <- (sorted[mid] + sorted[mid + 1] ) / 2 } else { mid <- (n + 1) / 2 median <- sorted[mid] } return(median) } calculate_median(c(2, 3, 4, 5 [instruction] | Implement an R program to calculate the median of an integer array. [input] | [2, 3, 4, 5]
[output] | <html> <head> <title>Table Example</title> </head> <body> <table> <tr> <td>Row 1, Column 1</td> <td>Row 1, Column 2</td> <td>Row 1, Column 3</td> </tr> <tr> <td>Row 2, Colu [instruction] | Create an HTML page with a table which contains three rows and three columns. [input] |
[output] | import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.input.KeyCode; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; public class MoveSquare extends Application { public static void [instruction] | Create a JavaFX program that allows a user to move a square shape in 3 different directions using the arrow keys. [input] |
[output] | class Employee { int age; string name; public: int getAge() { return age; } string getName() { return name; } void setAge(int age) { this->age = age; } void setName(string name) { this->name = name; } }; [instruction] | Create a C++ class called Employee with two data fields age and name. [input] |
[output] | def find_largest(nums): largest = nums[0] for num in nums: if num > largest: largest = num return largest [instruction] | Convert the following paragraph from English to Python code: "Given a list of numbers, find the largest number". [input] |
[output] | This code is trying to modify an immutable object (a tuple) as it is attempting to assign a value to the first element in a tuple. The correct way to do this is with a list, not a tuple. The code should be changed to: def foo(x): x[0] = 2 where the input x is a list instead of a tuple. [instruction] | Identify the bug in the following python code: def foo(x): x[0] = 2 [input] | [0, 1, 2]
[output] | Traceback (most recent call last): File "code.js", line 3, in <module> foo(2) File "code.js", line 1, in foo return n + 1 TypeError: unsupported operand type(s) for +: 'int' and 'str' [instruction] | Generate a stack trace for the following JavaScript code: function foo(n) { return n + 1; } foo(2); [input] |
[output] | for num in [1, 2, 3, 4]: print(num) [instruction] | Implement a for loop in Python to iterate through a given list of numbers. [input] | [1, 2, 3, 4]
[output] | This code implements a recursive function to compute the sum of numbers from 1 to n. Specifically, the base case is when n is 0, and the recursive case is when n is greater than 0. In the recursive case, the function will call itself with n-1 as the argument, and then adds n to the result of that ca [instruction] | Analyze the following code and explain what it does: def func(n): if n == 0: return 0 else: return n + func(n - 1) [input] |
[output] | This expression is a dictionary, which is a type of data structure in Python. A dictionary is a key-value pair, where the key is unique and the value can be a list of data items or a single item. In this example, the key is "name" and the value is "John", and the key is "age" and the value is 40. [instruction] | Identify the data type of the following Python expression: {"name": "John", "age": 40} [input] |
[output] | print("Hello") [instruction] | Rewrite the following code snippet in Python to print out the word "Hello": print("Hello") [input] |
[output] | A * (1.0 / B) [instruction] | Divide two floating-point numbers without using the '/' operator. [input] | A = 5.0, B = 3.0
[output] | SELECT DISTINCT name FROM employee; [instruction] | Create a SQL query that lists all entries from a table that have a given parameter in the distinct column. [input] | Table: employee Parameter: name
[output] | let obj = { message: "Hello, World" } [instruction] | Using Javascript, create an object that has a property of message with a value of "Hello, World" [input] |
[output] | public static int findMax(int num1, int num2) { return (num1 > num2) ? num1 : num2; } [instruction] | Create a method in Java that takes two integers and finds the maximum of them. [input] |
[output] | for (int i = 0; i <= n; i+=2) { cout << i << " "; } [instruction] | Create a for loop in C++ to print out all the even numbers from 0 to a given number. [input] |
[output] | let person = { "name": "John Doe", "age": 25, "address": "123 Main St, New York, NY 10001" } [instruction] | Construct an object in JavaScript to store the details of a person with the fields "name","age" and "address". [input] |
[output] | const Message = (props) => { return ( <div style={{color: props.color}}>{props.message}</div> ) } [instruction] | Create a React component that takes two props, a message and a color, and displays the message with the desired color. [input] |