[output] | var price = 100; var discount = 0.05; var finalPrice = price - (price * discount); console.log("Final Price: $" +finalPrice); [instruction] | Calculate the final price of a product after applying a 5% discount. [input] | Price: $100
[output] | function deleteItems(arr, itemToDelete) { return arr.filter(item => item !== itemToDelete); } let array = [1, 2, 3, 4, 5]; let itemToDelete = 3; let newArray = deleteItems(array, itemToDelete); console.log(newArray); // [1,2,4,5] [instruction] | Create a method to delete items from a specified array. [input] | Array: [1, 2, 3, 4, 5]
[output] | class MyClass { public: bool isUpper(string str) { for(int i = 0; i < str.length(); i++) { if (islower(str[i])) return false; } return true; } }; [instruction] | Implement a class method in C++ that takes a string parameter, checks to see if it is all uppercase, and outputs a Boolean value. [input] |
[output] | base_square = base * base height_square = height * height base_times_height = base * height area_numerator = base_square + height_square + base_times_height area_denominator = 2 area = area_numerator / area_denominator [instruction] | Generate five lines of code that will calculate the area of the following regular triangle. [input] | base = 5 height = 4
[output] | sum_of_array = sum(my_array) [instruction] | Create one line of code to sum the contents in a given array. [input] | my_array = [2, 3, 5, 7, 11]
[output] | for i in range(1, 6): print('*'*i) [instruction] | Construct a loop that will print the upside down triangle shape below. [input] | * ** *** **** *****
[output] | def get_length(param): return len(param) [instruction] | Implement a function that will take a parameter input and return the length of the parameter. [input] |
[output] | my_dict = dict(zip(my_dict.values(), my_dict.keys())) [instruction] | Construct a one-liner that takes a dictionary and reverses the keys and values of the dictionary. [input] | my_dict = {'Tony': 3, 'Peter': 4}
[output] | function isLeapYear(year) { return (year % 400 === 0) || ((year % 4 === 0) && (year % 100 != 0)); } [instruction] | Write a JavaScript function that checks if a given parameter is a leap year. [input] |
[output] | CREATE TABLE table_name ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, name VARCHAR(30) NOT NULL ); [instruction] | Design a MySQL table with two columns, id and name. [input] |
[output] | for i in range(n): for j in range(i+1): print('*', end=" ") print() [instruction] | Create a program that takes a number n and prints the pattern given below. [input] | n = 3
[output] | def get_complement(lst): return [1 - item for item in lst] [instruction] | Alter the following program such that it returns the complement of the given list. [input] | def get_complement(lst): new_lst = [] for i in range(len(lst)): new_lst.append(1 - lst[i]) return new_lst
[output] | def quicksort(nums): if len(nums) <= 1: return nums else: pivot = nums[0] less = [i for i in nums[1:] if i <= pivot] greater = [i for i in nums[1:] if i > pivot] return quicksort(less) + [pivot] + quicksort(greater) print(quicksort([52,85,23,6,37,77]) [instruction] | Implement a quicksort algorithm in Python to sort a list of 6 integers [52,85,23,6,37,77]. [input] | [52,85,23,6,37,77]
[output] | Random r = new Random(); int[][] arr = new int[3][3]; for (int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++){ arr[i][j] = r.nextInt(); } } [instruction] | Generate a random 3x3 array using Java. [input] |
[output] | SELECT title, price FROM Books; [instruction] | Construct a SQL query to list the titles and prices of books from the "Books" table. [input] |
[output] | #include <iostream> #include <math.h> using namespace std; int main() { double n = 150; cout << "The square root of " << n << " is: " << sqrt(n) << endl; return 0; } [instruction] | Compute the square root of 150 using C++. [input] |
[output] | if (age < 18) { console.log("You are not old enough to access this page."); } else { console.log("Welcome to the page!"); } [instruction] | Construct an if/else statement in Javascript to display a message depending on the value of a variable called "age". [input] | let age = 17
[output] | getUserData(userData => { getPosts(userData.username, posts => { displayPosts(posts); }); }); [instruction] | Rewrite the code to make it run asynchronously in Node.js. [input] | const userData = getUserDataSync(); const posts = getPostsSync(userData.username); displayPosts(posts);
[output] | <?php $ary = [2, 3, 8, 9]; $sum = 0; foreach ($ary as $value) { $sum += $value; } echo "The sum is " . $sum; ?> [instruction] | Construct a loop in PHP to add all elements from an array [2, 3, 8, 9]. [input] | [2, 3, 8, 9]
[output] | def linear_search(arr, target): for i in range(len(arr)): if arr[i] == target: return i return -1 # target not found [instruction] | Write a function to search in a 1D array of integers, and return the index of the target if it is present. [input] | arr = [1, 4, 5, 6, 7, 9, 3, 2] target = 8
[output] | <h1><b><i>Hello World</i></b></h1> [instruction] | Edit the following html code by bolding and italicizing the "Hello World" text. [input] | <h1>Hello World</h1>
[output] | def count_primes(n): count = 0 for i in range(2, n+1): is_prime = True for j in range(2, i): if i % j == 0: is_prime = False break if is_prime: count += 1 return count [instruction] | Write a function to return the count of all prime numbers from 1 to n (inclusive). [input] |
[output] | Example of a sorting algorithm in Python: def selection_sort(arr): for i in range(len(arr)): # Find the minimum element in remaining # unsorted array min_idx = i for j in range(i + 1, len(arr)): if arr[min_idx] > arr[j]: min_idx = j [instruction] | Find an example of a sorting algorithm in Python. [input] |
[output] | user = { 'name': 'John Doe', 'email': 'jdoe@example.com', 'profile_image': 'https://example.com/images/jdoe.png' } [instruction] | Create a MongoDB document to store a user's profile with the following information: name, email, profile_image. [input] | name = "John Doe" email = "jdoe@example.com" profile_image = "https://example.com/images/jdoe.png"
[output] | import csv def json_to_csv(data): csv_data = [list(data.values())] with open('data.csv', 'w') as f: writer = csv.writer(f) writer.writerows(csv_data) json_to_csv(data) [instruction] | Suggest a way of converting the following JSON object into CSV format. [input] | data = { "Name": "John Doe", "Age": "50", "Gender": "Male" }
[output] | def intToRoman(num): val = [ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 ] rom_num = [ "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", [instruction] | Write a function to convert a given integer number toRoman numerals. [input] |
[output] | function checkStringLength(str) { return str.length > 5; } [instruction] | You need to code a function in JavaScript that takes in a string and checks if the length of string is greater than 5 characters. [input] |
[output] | public static boolean checkDuplicates(int[] arr) { Set<Integer> set = new HashSet<>(); for(int number : arr ) { if(!set.add(number)) { return true; } } return false; } [instruction] | Code an algorithm in Java to check if a given array contains duplicate elements. [input] | arr = [3, 6, 5, 4, 6, 9]
[output] | SELECT a.job_role, a.emp_name, a.salary FROM employees a INNER JOIN ( SELECT job_role, MAX(salary) car_max FROM employees GROUP BY job_role ) b ON a.job_role=b.job_role AND a.salary=b.car_max; [instruction] | Create a SQL query to find the employees with the highest salary in each job role. [input] |
[output] | // reversing the linked list Node* reverse(Node* head) { Node* prev = NULL; Node* current = head; Node* next; while (current != NULL) { // Store next next = current->next; // Reverse current node's pointer current->next = prev; [instruction] | Develop an algorithm in C++ to reverse a linked list. [input] |