[output] | def shuffle_nums(nums): from random import shuffle shuffle(nums) return nums [instruction] | Write a Python function to shuffle (randomly reorder) a list of numbers [input] | nums = [1, 2, 3, 4, 5]
[output] | func daysBetween(date1: Date, date2: Date) -> Int { let components = Calendar.current.dateComponents([.day], from: date1, to: date2) return components.day! } [instruction] | Design a Swift program to determine the number of days between two dates. [input] | date1 = Date(year: 2019, month: 10, day: 15) date2 = Date(year: 2020, month: 5, day: 1)
[output] | String[][] newdataset = new String[2000][2]; for(int i=0; i< 2000; i++){ newdataset[i][0] = dataset[i][0]; //Name newdataset[i][1] = dataset[i][1]; //Class } [instruction] | Given a dataset containing multiple columns (Name, Class, and Subject) of 2,000 students, write a Java program to output a new dataset that only contains the "Name" and "Class" columns. [input] | Name | Class | Subject Adam | 1A | Math Jane | 2B | Physics Tom | 3A | English
[output] | String text = "The quick brown fox"; String newString = text.replaceAll("\\s+",""); System.out.println(newString); // Output: Thequickbrownfox [instruction] | Write a script to remove any white spaces in a text string. [input] | The quick brown fox
[output] | base = 8 height = 6 hypotenuse = (base**2 + height**2)**0.5 print(hypotenuse) // Output: 10.0 [instruction] | Write a Python program to calculate the hypotenuse of a right triangle with base and Height of 8 and 6 respectively. [input] |
[output] | function formatDate(inputDate){ let date = new Date(inputDate); let weekday = ["Sun", "Mon", "Tue", "Wed","Thur", "Fri","Sat"]; let day = weekday[date.getDay()]; let month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep","Oct", "Nov", "Dec"]; let monthName = month[date [instruction] | Create a JavaScript function to convert a date string of the form "DD/MM/YYYY" to a different string format, "Weekday, Month dd yyyy". [input] | "14/08/2020"
[output] | SELECT COUNT(medicines.name) FROM medicines WHERE date BETWEEN 'date1' AND 'date2' GROUP BY date; [instruction] | Write a SQL query to identify the number of medicines sold per day between two dates. [input] |
[output] | SELECT product_name, SUM(quantity) AS total_quantity FROM sales GROUP BY product_name ORDER BY total_quantity DESC LIMIT 1; [instruction] | Write an SQL query to identify the product with the most sales quantities in a given dataset [input] |
[output] | #include <stdio.h> #include <string.h> void camelCaseToPascalCase(char str[]) { int i = 0; if (str[0] >= 'a' && str[0] <= 'z') str[0] = str[0] - 32; while (str[i] != '\0') { if (str[i] == ' ') { i++; if (str[i] >= 'a' && s [instruction] | Create a C language function to convert a string in camelCase to a string in PascalCase [input] | camelCase
[output] | #include <stdio.h> void insertNum(int arr[], int n, int x, int i) { int j; for (j = n - 1; j >= i; j--) arr[j + 1] = arr[j]; arr[i] = x; } int main() { int arr[] = {1, 2, 3, 4}, x = 5, i = 2, n = 4; insertNum(arr, n, x, i); int j; for (j = 0; j < n + [instruction] | Given an array of numbers, write a C program to insert a given number "x" at the index "i" and push back all the previous numbers by 1. [input] | arr = [1, 2, 3, 4], x = 5, i = 2
[output] | function divisors(num){ let result = []; for (let i = 1; i <= num; i++){ // 1, 2, 3... num if (num % i === 0){ if (i != num){ result.push(i); } } } return result; } console.log(divisors(12)); //Output: [1, 2, 3, 4, 6] [instruction] | Using JavaScript, create a function to output all the divisors of a given number, without the number itself. [input] | 12
[output] | UPDATE items SET price = 50 WHERE price > 50; [instruction] | Write a MySQL query to update the price of all items that cost more than $50 to $50. [input] |
[output] | import string import random def generate_random_string(n): """ Generate a random string with the length n """ return ''.join(random.choices(string.ascii_letters + string.digits, k=n)) print(generate_random_string(10)) [instruction] | Generate a random string with the specified length n. [input] | n=10
[output] | def search_list(nums, target): """ Function to search a list of integers and print the index of the first matched item """ for i in range(len(nums)): if nums[i] == target: return i return -1 print(search_list([4, 7, 1, 2, 5], 7)) [instruction] | Write a code to search a list of integers and print the index of the first matched item. [input] | nums=[4, 7, 1, 2, 5], target=7
[output] | def generate_array(n): """ Generate an array of increasing numbers beginning from 1 of length n """ return [i for i in range(1, n+1)] print(generate_array(5)) [instruction] | Generate an array of increasing numbers beginning from 1 of length n. [input] | n=5
[output] | [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 25]] [instruction] | Given a positive integer n, print out an nxn matrix filled with numbers counting up from 1 to n x n. [input] | 5
[output] | combinations = [] for i in list1: for j in list2: combinations.append([i, j]) print(combinations) # Output: [[1, 4], [1, 5], [1, 6], [2, 4], [2, 5], [2, 6], [3, 4], [3, 5], [3, 6]] [instruction] | Write a code in Python to output all the combinations of two given lists. [input] | list1 = [1, 2, 3] list2 = [4, 5, 6]
[output] | list_sum = 0 for num in list1: list_sum += num print(list_sum) # Output: 15 [instruction] | Find the sum of all elements from the following list. [input] | list1 = [1, 2, 3, 4, 5]
[output] | def compress_string(string): current_char = string[0] compressed_string = current_char count = 1 for char in string[1:]: if char == current_char: count += 1 else: compressed_string = compressed_string + str(count) + char current_ [instruction] | Create an algorithm to compress a string by removing consecutive duplicate characters. [input] | string = "aabcccccaaa"
[output] | class Circle: def __init__(self, radius, color): self.radius = radius self.color = color def getArea(self): return 3.14 * self.radius * self.radius def getCircumference(self): return 2 * 3.14 * self.radius [instruction] | Construct a Python class to model a circle. [input] |
[output] | def count_occurrence(number, input_list): return input_list.count(number) [instruction] | Generate a function in Python that takes a number and a list as input and finds the number of occurrences of the number in the list. [input] |
[output] | def fahren_to_celsius(fahren): celsius = (fahren - 32) * (5 / 9) return celsius print(fahren_to_celsius(50)) # Output: 10.0 [instruction] | Create a script in Python to convert fahrenheit temperatures to celsius. [input] |
[output] | The solution of this Linear Programming problem is x = 40 and y = [instruction] | Solve the following linear programming problem: Maximize x + y Subject to: 2x + 3y ≤ 120 x + 2y ≤ 100 x ≥ 0, y ≥ 0 [input] |
[output] | Linear search is an algorithm for finding a particular value in an array. It works by sequentially going through each item in the array, comparing the desired value with each item until it is either found or the end of the array is reached. If the item is found, it's index in the array is returned, [instruction] | Explain the algorithm used in linear search. [input] |
[output] | def divide_nums(a, b): try: return a / b except ZeroDivisionError as e: print('Error:', e) logging.error('An error occurred during division.') [instruction] | Edit this Python program so that it logs a message whenever an error occurs. [input] | def divide_nums(a, b): try: return a / b except ZeroDivisionError as e: print('Error:', e)
[output] | def double_list(original_list): return [item * 2 for item in original_list] [instruction] | Rewrite this function in Python to take advantage of list comprehensions. [input] | def double_list(original_list): doubled_list = [] for item in original_list: doubled_list.append(item * 2) return doubled_list
[output] | // Load MySQL var mysql = require("mysql"); // Create connection var con = mysql.createConnection({ host: "localhost", user: "user", password: "password", database: "my_db" }); // Connect to MySQL con.connect(function(err) { if (err) throw err; console.log("Connected to MySQL!"); }); [instruction] | Create an API using Node.js that returns the average height of all users from a MySQL database. [input] |
[output] | <form action="/action_page.php" method="post"> Name:<br> <input type="text" name="name" value=""><br> Address:<br> <input type="text" name="address" value=""><br> <input type="submit" value="Submit"> </form> [instruction] | Create an HTML form to take input of a student's name and address. [input] |
[output] | for count in range(1, 11): print(count) [instruction] | Create a for loop that counts up to the given number. [input] | Number: 10
[output] | Incrementing is referred to as "incrementing by one" or "incrementing by one unit". [instruction] | What is the term used to refer to the action of incrementing a value by one? [input] |