[output] | System.out.println("Hello World!"); [instruction] | Rewrite the following line of code in a Java syntax. [input] | console.log("Hello World!");
[output] | <!DOCTYPE html> <html> <head> <title>My Favorite Color</title> </head> <body> <h1 style="color: blue;">My favorite color is blue</h1> </body> </html> [instruction] | Write an HTML page that displays the text "My favorite color is blue" in a blue font. [input] |
[output] | def divide(num1, num2): if num2 == 0: print('Error: Invalid operation. num2 cannot be zero.') else: result = num1 // num2 return result [instruction] | Edit the following code so that it prints an appropriate error message. [input] | def divide(num1, num2): result = num1 // num2 return result
[output] | The following are valid Python operators: '+', '-', '*', '/', '%', '//', '**', '&', '|', '^', '<<', '>>'. [instruction] | Which of the following is a valid operator in Python? [input] |
[output] | The function "square" is a pure function because it only relies on its input and does not modify any external state. The function "add_one" is an impure function because it modifies an external (i.e. the list "nums") state. [instruction] | Classify the following functions as pure or impure. [input] | def square(x): return x*x def add_one(nums): for i in range(len(nums)): nums[i] += 1 return nums
[output] | Yes, the code fragment passes the test since the function "my_func" successfully returns the value 5 when given arguments a=2 and b=3. [instruction] | Does the following code fragment pass the test? [input] | def my_func(a, b): return a + b def test_my_func(): assert(my_func(2, 3) == 5)
[output] | def to_title_case(sentence): words = sentence.split() titlecase_words = [] for word in words: titlecase_words.append(word.title()) return ' '.join(titlecase_words) [instruction] | Implement a function in Python to convert a given sentence into title case. [input] | This is a sentence.
[output] | public class point3D { int x; int y; int z; } [instruction] | Construct a declaration in Java to store the coordinates of a point in 3D space. [input] |
[output] | public List<string> FilterList(List<string> inputList, string condition) { List<string> filteredList = new List<string>(); foreach(string str in inputList) { if(str.StartsWith(condition)) { filteredList.Add(str); } } return filteredList; } [instruction] | Develop a service handler in C# to filter the records of a list to find the ones that satisfy a certain condition. [input] | List of strings - ['apple', 'car', 'cat', 'dog'] Condition - Starts with the letter 'c'
[output] | #include <stdio.h> #include <string.h> int main(){ char str[20] = "Hello"; printf("%-20s\n", str); return 0; } [instruction] | Generate a C code snippet to print a given string with a width of 20 characters. [input] | Hello
[output] | $name = $_POST["Name"]; $age = $_POST["Age"]; $query = "INSERT INTO user (Name, Age) VALUES ('$name', '$age')"; if (mysqli_query($conn, $query)) { // Success } else { //error } [instruction] | Compose a PHP code to store the data entered by the user into a database. [input] | Name - John Smith Age - 30
[output] | function toScientificNotation(number) { return number.toExponential(); } [instruction] | Design a JavaScript function to convert the given number in scientific notation. [input] | 1000.003
[output] | function frequency(str) { let count = {}; str.split("").forEach(function(s) { count[s] ? count[s]++ : count[s] = 1; }); return count; } [instruction] | Develop an algorithm in JavaScript to calculate the frequency of each character in a given string. [input] | Hello
[output] | * { font-weight: bold; } [instruction] | Compose a CSS code to make all the text elements bold. [input] |
[output] | monthdays <- as.numeric(format(as.Date(Sys.Date()), format='%d')) cat("There are", monthdays, "days in the current month.") [instruction] | Write an R script to find the number of days in the current month. [input] |
[output] | SELECT * FROM students WHERE age > 25; [instruction] | Design a SQL query to select students older than 25 years from a database. [input] |
[output] | # set a range for the numbers min = 10 max = 20 # iterate and print odd numbers for num in range(min,max+1): if num % 2 != 0: print(num, end=" ") [instruction] | Design a Python program to identify odd numbers in a given range. [input] | 10-20
[output] | db.collection.find( { state: "CA" } ) [instruction] | Create a MongoDB query to get all the documents from the collection where the state is 'CA'. [input] |
[output] | SELECT * FROM users WHERE first_name = 'John' AND last_name = 'Doe'; [instruction] | Create a MySQL query to find all users whose first name is 'John' and last name is 'Doe'. [input] |
[output] | public class Combinations { static void printCombinations(int[] arr, int index, int num, int reducedNum) { if (reducedNum < 0) return; if (reducedNum == 0) { for (int i = 0; i < index; i++) System.out.print(arr[i] + " "); [instruction] | Write a Java program to print out all possible combinations of the numbers from 0 to 9 [input] |
[output] | SELECT name, age FROM users WHERE age > 25; [instruction] | Create a SQL query to get the names and ages of all the users with an age greater than 25. [input] |
[output] | To add a simple login feature, you will need to create a page with a form that will take the username and password input from the user. The form should contain an input field for the username, an input field for the password, and a submit button. The page should also include an action link to a page [instruction] | Add a simple login feature to a given website. [input] | A given website with HTML and CSS content
[output] | Using a programming language such as Python, first use the JSON library to decode the JSON data. Then use a library such as Openpyxl or XlsxWriter to write the data from the JSON object into an Excel spreadsheet. [instruction] | Convert the given JSON data into an Excel spreadsheet. [input] | { "products": [ { "id": 1, "name": "Apple", "price": 3.50 }, { "id": 2, "name": "Orange", "price": 2.50 }, { "id": 3, "name": "Banana", "price": 1.25 } ] }
[output] | total = 0 for i in [1, 2, 3, 4, 5]: total += i print(total) # the output will be 15 [instruction] | Construct a for loop in Python for summing up the elements of a given list. [input] | List of integers: [1, 2, 3, 4, 5]
[output] | #include<stdio.h> int main() { int rowStart=0, rowEnd=2, colStart=0, colEnd=2; int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; while (rowStart < rowEnd && colStart < colEnd) { //Print the first row for (int i=colStart; [instruction] | Write a C program to print the elements of a given matrix in spiral order. [input] | matrix: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
[output] | def is_unique(list_items): s = set(list_items) if len(list_items) == len(s): return True else: return False print(is_unique(list_items)) # The output will be False [instruction] | Create a Python program to check if all items in a list are unique. [input] | list_items = [1,2,3,2,3]
[output] | Using the regular expression library re in Python, you can extract numbers from a given string. For example, import re string = "My age is 22 and my lucky number is 7" matches = re.findall(r'\d+', string) # matches will be [22, 7] [instruction] | How to extract numbers from a given string in Python? [input] |
[output] | Memory management in C is a process of controlling and coordinating the use of memory in a program or operating system. It involves allocating and deallocating memory as needed. The main purpose of memory management is to provide ways of managing memory usage such that a program can run correctly an [instruction] | What is memory management in C? [input] |
[output] | Debugging is the process of finding and fixing errors in a program's code. In C programming, debugging involves finding and fixing syntax errors, logical errors, and runtime errors. To debug a C program, you must use a debugging tool such as a debugger or a print statement. The debugging process inv [instruction] | Describe the process of debugging in C programming. [input] |
[output] | def bubble_sort(nums): # Traverse through all array elements for i in range(len(nums)): # Last i elements are already in place for j in range(0, len(nums)-i-1): # traverse the array from 0 to n-i-1 # Swap if the element found is greater # than the next element [instruction] | Sort an array of integers in ascending order by implementing a Bubble Sort algorithm. [input] | unsorted_list = [8, 5, 3, 1, 9, 6, 0, 7, 4, 2, 5]