[output] | float average(float num1, float num2) { return (num1 + num2) / 2; } [instruction] | Write a function in C that takes two float numbers as input and returns their average. [input] |
[output] | def list_sum(num_list): # initialize sum Sum = 0 # traverse through all numbers for num in num_list: Sum += num # return Sum return Sum # test the above code list1 = [1,2,3,4,5] print(list_sum(list1)) # Output: 15 [instruction] | Create a function in Python which takes in a list of numbers and returns the sum of all numbers. [input] | [1,2,3,4,5]
[output] | 5 [instruction] | How many elements does the following array contain? [input] | Array: [4, 6, 1, 9, 7]
[output] | "November 10, 2008" [instruction] | Format the given date string using JavaScript. [input] | String: 2008-11-10
[output] | -9 [instruction] | Subtract the given list of numbers using JavaScript. [input] | List: [8, 3, 6]
[output] | def get_unique_elements(list1, list2): unique_elements = [] for element in list1: if element not in list2: unique_elements.append(element) for element in list2: if element not in list1: unique_elements.append(element) return unique_elements [instruction] | Create a final list of all unique elements in list_1 and list_2. [input] | list_1 = [1, 2, 3, 4, 5] list_2 = [2, 4, 6, 8, 10]
[output] | \b[Aa]\w+\b [instruction] | Create a regular expression to select all words starting with 'a'. [input] |
[output] | let str1 = "Hello "; let str2 = "World!"; let str3 = " How are you?"; const concatString = str1.concat(str2, str3); console.log(concatString); // "Hello World! How are you?" [instruction] | Write a JavaScript program to compute the value obtained by concatenating the three given strings. [input] | str1 = "Hello " str2 = "World!" str3 = " How are you?"
[output] | SELECT name, length_of_service FROM employees ORDER BY length_of_service DESC LIMIT 5; [instruction] | Create a SQL statement to select the five longest-serving employees. [input] |
[output] | $user = New-Object System.Security.Principal.WindowsPrincipal($User) if ($user.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Host "You are already an Administrator" } else { Start-Process "powershell.exe" "-NoExit -Command Start-Process PowerShell.exe -Verb run [instruction] | Escalate privileges in a Windows system using PowerShell. [input] |
[output] | def get_frequency_map(string): frequency_map = {} # count the frequency of each character for char in string: if char in frequency_map: frequency_map[char] += 1 else: frequency_map[char] = 1 return frequency_map string = "hello world" frequ [instruction] | Write a function to parse a string and return a dictionary where each character in the string is mapped to its frequency. [input] | "hello world"
[output] | SELECT COUNT(*) FROM customers WHERE country = '<country name>'; [instruction] | Create a MySQL query to find the total number of customers from a certain country. [input] |
[output] | SELECT Title, Price, Quantity FROM Library WHERE Type = 'Book'; [instruction] | Write a SQL query to find information about books in a library [input] |
[output] | [x for x in list if x >= 0] [instruction] | Find all the elements in a Python list that correspond to a certain condition using list comprehension [input] | list = [-3, -2, -1, 0, 1, 2, 3]
[output] | 14 [instruction] | Evaluate an expression written in reverse Polish notation [input] | 5 1 2 + 4 * + 3 -
[output] | [ "New York City, NY", "Washington, DC", "Los Angeles, CA", "Chicago, IL" ] [instruction] | Normalize a dataset of strings [input] | [ "New York City, NY", "Washington, D.C.", "Los Angeles, Ca", "Chicago, Il" ]
[output] | 50 / \ 30 70 / \ / \ 10 40 60 80 / 20 [instruction] | Construct a tree which follows the pre-order traversal [input] | 50, 30, 10, 20, 40, 70, 60, 80
[output] | class NeuralNetwork: def __init__(self, num_inputs, num_hidden_layers, num_outputs): self.num_inputs = num_inputs self.num_hidden_layers = num_hidden_layers self.num_outputs = num_outputs self.weights_input_to_hidden = np.random.randn(num_inputs, num_hidden_layers) self.bias_ [instruction] | Implement a neural network from scratch [input] |
[output] | ^(.)(?:(.)(?<=\2))?\1?$ [instruction] | Create a regular expression to determine if a word is in the form of a palindrome. [input] |
[output] | #include <algorithm> #include <iostream> #include <vector> int main() { // Create sample array std::vector<int> arr = {3, 10, 2, 6, 4}; // Sort array std::sort(arr.begin(), arr.end()); // Get kth largest element int kth_largest = arr.end()[-2]; // second to last elemen [instruction] | Given the following array, write a program to find the kth largest element. [input] | arr = [3, 10, 2, 6, 4], k = 2
[output] | #include <iostream> #include <string> bool is_palindrome(std::string str) { int i = 0; int j = str.length() - 1; while (i < j) { if (str[i] != str[j]) return false; i++; j--; } return true; } int main() { std [instruction] | You've been asked to create a program to determine whether a given string is a palindrome [input] | str = "madam"
[output] | #include <iostream> #include <string> void print_vowels(std::string str) { for (int i = 0; i < str.length(); i++) { if (str[i] =='a' || str[i] =='e' || str[i] =='i' || str[i] =='o' || str[i] =='u'||str[i] =='A' || str[i] =='E' || str[i] =='I' || str[i] == [instruction] | Create a program that prints the vowels in a string. [input] | str = "Hello World!"
[output] | #include <iostream> #include <string> void replace_chars(std::string& str, char find, char replace) { for (int i = 0; i < str.size(); i++) { if (str[i] == find) str[i] = replace; } } int main() { std::string str = "happy happy"; char find = 'p'; c [instruction] | You've been asked to edit a string by replacing all occurrences of a certain character with another character. [input] | string = "happy happy" find = "p" replace = "s"
[output] | 1. 5 + 5 2. document.write("Hello World!") 3. function greet(){ console.log("Hello World!") } [instruction] | Identify three expressions that are valid in JavaScript. [input] |
[output] | function isPalindrome(word) { let revWord = word.split('').reverse().join(''); return word == revWord; } [instruction] | Given the parameter 'word', what JavaScript code should be written to check whether it is a palindrome or not? [input] |
[output] | odds = [] for num in list: if num % 2 != 0: odds.append(num) [instruction] | Write Python code to store odd numbers from the given list in a separate list. [input] | list = [1, 2, 3, 4, 5, 6, 7]
[output] | UPDATE employees SET salary = salary + 100 WHERE id = 100; [instruction] | Write a SQL statement to update the 'salary' of an employee with the id value of '100' by 100. [input] |
[output] | conn = mysql.connector.connect( host="localhost", user="root", passwd="12345" database="test" ) cursor = conn.cursor() cursor.execute("INSERT INTO users(name, email, age) VALUES('John Doe', 'johndoe@example.com', 28)") conn.commit() [instruction] | Modify the given code snippet to add a new entry in the users table of a MySQL database. [input] | conn = mysql.connector.connect( host="localhost", user="root", passwd="12345" database="test" )
[output] | <ul> <li>apple</li> <li>banana</li> <li>cherry</li> </ul> [instruction] | What HTML code is needed to print each item in the following list? [input] | list = ["apple", "banana", "cherry"]
[output] | SELECT state, COUNT(*) FROM employees GROUP BY state; [instruction] | Construct a SQL query to count the number of employees with the same 'state' value in the employees table. [input] |