[output] | A dictionary could be used to store the student details. Each key could be the student's name, and each value could be a tuple containing the student's age, grade and classes. student_data = { 'John' : (15, 8, ['Math', 'English']), 'Mary' : (14, 7, ['Science', 'History']) } [instruction] | Suggest a data structure to store the student details for a school. [input] |
[output] | import re # Zip code should consist of four digits. zip_code_regex = re.compile(r'\d{4}') [instruction] | Write a regular expression to match a 4 digit zip code. [input] |
[output] | aws dynamodb create-table --table-name Users --attribute-definitions AttributeName=UserID,AttributeType=S --key-schema AttributeName=UserID,KeyType=HASH --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 [instruction] | Create a DynamoDB table called "Users" with a primary key as "UserID". [input] |
[output] | String[] output = new String[4]; for(int i = 0; i < strings.length; i++) { output[indices[i]] = strings[i]; } System.out.println(Arrays.toString(output)); [instruction] | Create a program that takes two inputs, an array of strings and an array of integers. Output an array with the strings at the same indices as the integers. [input] | String[] strings = {"cat", "dog", "bird", "fish"}; int[] indices = {1, 0, 3, 2};
[output] | void bubbleSort(int array[]) { int temp; for(int i = 0; i < array.length; i++) { for(int j = 0; j < array.length - 1; j++) { if(array[j] > array[j+1]) { temp = array[j]; array[j] = array[j+1]; array[j+1] = temp; } } } } [instruction] | Recreate a function that sorts the elements of an array using bubble sort. [input] | int[] array = {4, 3, 6, 5, 1, 2};
[output] | int smallestPositive = Integer.MAX_VALUE; for (int i = 0; i < array.length; i++) { if (array[i] > 0 && array[i] < smallestPositive) { smallestPositive = array[i]; } } System.out.println(smallestPositive); [instruction] | Given an array with negative and positive numbers, create a function to find the smallest positive number inside the array. [input] | int[] array = {-3, -2, -1, 1, 2, 3, 4};
[output] | int[][][] array3D = new int[4][4][4]; [instruction] | Create a code that creates a 3D array of size 4x4x4. [input] |
[output] | SELECT AVG(Salary) FROM Employees; [instruction] | Write a SQL query that finds the average of a given table's "Salary" column. [input] |
[output] | SELECT zone, SUM(price*quantity) AS 'Total Order Value' FROM orders JOIN zones ON orders.zone_id = zones.zone_id GROUP BY zone; [instruction] | Write an SQL query that calculates the total order value for each delivery zone in the ‘zones’ table. [input] |
[output] | #!/bin/bash TMP_STR="" for i in {1..3} do RANDOM_NUM=$((RANDOM % 26 + 65)) CHAR=$(printf "\x$(printf %x $RANDOM_NUM)") while [[ $TMP_STR =~ $CHAR ]] do RANDOM_NUM=$((RANDOM % 26 + 65)) CHAR=$(printf "\x$(printf %x $RANDOM_NUM)") done TMP_STR+=$CHAR done echo $TMP_STR [instruction] | Create a bash script that generates a random 3 letter string with no duplicates in it. [input] |
[output] | SELECT MAX(salary) FROM employees; [instruction] | Write a sql query that takes the maximum of a particular column [input] | Table: employees Columns: name, salary
[output] | import numpy as np from sklearn.linear_model import LinearRegression # Data X_train = np.array([1, 2, 3, 4, 5]).reshape(-1, 1) y_train = np.array([6, 12, 18, 24, 30]) # Model model = LinearRegression() model.fit(X_train, y_train) # Prediction side_length = 3 pred = model.predict([[side_length] [instruction] | Create a machine learning model in Python to predict the total surface area of a cube given its side length [input] | side_length = 3
[output] | int a; if (a == 0) { } [instruction] | Correct the following C++ code by adding missing syntax. [input] | int a; if (a == 0
[output] | /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/ [instruction] | Write a regular expression in JavaScript to check the validity of an email. [input] |
[output] | def uniq_array(arr) return arr.uniq end [instruction] | Write a Ruby function that takes an array as input and returns a new array with only unique elements [input] | [1, 2, 2, 3, 4, 5]
[output] | #!/bin/bash folder_name="my_folder" mkdir $folder_name [instruction] | Create a bash script to create a folder with a given name [input] | folder_name = my_folder
[output] | <html> <head> <title>Input and Compare Strings</title> </head> <body> Enter two strings: <input type="text" id="str1" /> <input type="text" id="str2" /> <input type="button" value="Submit" onclick="compareStrings()" /> <div id="result"/> <script> function comp [instruction] | Create a HTML page that takes two text strings as inputs and outputs the longest one. [input] |
[output] | public class PrintPhrase { public static void main(String[] args) { for (int i = 0; i < 5; i++) { System.out.println("Hello world!"); } } } [instruction] | In Java, write a program that prints a certain phrase five times. [input] |
[output] | ^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$ [instruction] | Produce a regex pattern to validate a US phone number format [input] |
[output] | var lastFour = myString.slice(-4); [instruction] | Write a JavaScript statement to extract the last four characters from the string [input] | This is a sample string.
[output] | median(x) [instruction] | Compose an R expression to determine the median of a vector [input] |
[output] | SELECT county, COUNT(*) AS 'Number of Customers' FROM Customers GROUP BY county; [instruction] | Write a SQL query to generate a table that contains the number of customers per county [input] |
[output] | def print_longest_word(words): longest_word = "" for word in words: if len(word) > len(longest_word): longest_word = word print(longest_word) words = ["hello", "cat"] print_longest_word(words) if len(words) > 0: longest_word = words[0] for word in words: if len(word) > len(longest_word): l [instruction] | Edit this code to fix the bug in the program [input] | def print_longest_word(words): longest_word = "" for word in words: if len(word) > len(longest_word): longest_word = word print(longest_word) words = ["hello", "cat"] print_longest_word(words)
[output] | s = "Hello World!" index = 5 print("Character at index", index, "is:", s[index]) Output: Character at index 5 is: W [instruction] | Print the character at the specified index in a given string. [input] | s = "Hello World!" index = 5
[output] | def classify_sentence(sentence): if "bad" in sentence: return "negative" else: return "positive" # Driver code sentence = "The movie was bad" print("Sentence is classified as:", classify_sentence(sentence)) Output: Sentence is classified as: negative [instruction] | Create a function to classify the following sentence into "positive" or "negative". [input] | The movie was bad
[output] | def reverseList (list): list.reverse() return list reverseList(myList) # Returns [4, 3, 2, 1] [instruction] | Create a function in Python that takes one parameter, a list, and outputs the list in reverse. [input] | myList = [1, 2, 3, 4]
[output] | if ($x > $y) echo $x; else echo $y; [instruction] | With a PHP script, compare two numerical values and return the largest of the two. [input] | $x = 9; $y = 12;
[output] | SELECT * FROM products WHERE price > 10; [instruction] | Write a MySQL query to select all the products that have a price greater than 10. [input] |
[output] | String lowerString = myString.toLowerCase(); System.out.println(lowerString); // Outputs "hello world" [instruction] | With a Java program, convert a string to all lowercase letters. [input] | myString = "HeLlO WoRlD"
[output] | odds = [] for num in arr: if num % 2 == 1: odds.append(num) print(odds) [instruction] | You are given a list of numbers. Construct a for loop to filter out the odd numbers from the list. [input] | arr = [1,2,3,4,5]