[output] | def remove_vowels(string): vowels = {'a', 'e', 'i', 'o', 'u'} return ''.join(c for c in string if c not in vowels) [instruction] | Given a string, write a Python function that will remove all the vowels from it. [input] |
[output] | def check_number(number, condition): if condition and number % 2 == 0: return "yes" else: return "no" [instruction] | Create a Python function that takes two arguments, a positive integer and a boolean, and return the word "yes" if the boolean is true and the number is even, else it should return the word "no". [input] |
[output] | The factorial of 7 is 5040. [instruction] | Output the factorial of 7 [input] |
[output] | def find_max_product(nums): max_product = 0 for i in range(len(nums)): for j in range(i+1, len(nums)): product = nums[i] * nums[j] if product > max_product: max_product = product return max_product [instruction] | Create a Python function to find the pair of numbers that have the highest product in an array of numbers [input] | [1, 2, 4, 8, 10]
[output] | using System; namespace StringLength { class Program { static void Main(string[] args) { Console.WriteLine("Please enter a string: "); string input = Console.ReadLine(); Console.WriteLine($"The length of the string is: {input.Length}"); [instruction] | Create a C# program that takes a string input from the user and outputs its length. [input] |
[output] | function sumOfNumInRange(n) { let total = 0 for (let i=1; i<=n; i++) { total += i; } return total; } [instruction] | Write a JavaScript function that takes a number as an argument and finds the sum of all the numbers in a given range (based on the given number). [input] |
[output] | #include<stdio.h> int main() { int a[10]; for (int i = 0; i < 10; i++) scanf("%d", &a[i]); return 0; } [instruction] | Write a scanf for an integer array of size 10. [input] |
[output] | An array of objects can be created using the syntax below: let arrayOfObjects = [ { key1: 'value1', key2: 'value2' }, { key1: 'value3', key2: 'value4' }, { key1: 'value5', key2: 'value6' } ]; [instruction] | What is the syntax required to create an array of objects using JavaScript? [input] |
[output] | SELECT * FROM users WHERE username LIKE 'S%'; [instruction] | Write a SQL query to select users who have a username that starts with "S". [input] |
[output] | An array is a static data structure, while an array list is a dynamic data structure. An array has a fixed size which cannot be changed, while an array list can be dynamically resized. Elements in an array must be of the same type, while an array list can store elements with different types. Arrays [instruction] | Explain the differences between an array and an arraylist in Java. [input] |
[output] | def count_characters(stringList): count = 0 for string in stringList: count += len(string) return count [instruction] | How would you create a function that takes a list of strings as an argument and returns the total number of characters in all the strings together? [input] |
[output] | result = "positive" if x > 0 else "negative" [instruction] | Rewrite the following code to use the ternary operator in Python: if x > 0: result = "positive" else: result = "negative" [input] |
[output] | import keras model = keras.Sequential() model.add(keras.layers.Dense(256, activation="relu", input_dim=20)) model.add(keras.layers.Dense(128, activation="sigmoid")) model.add(keras.layers.Dense(64, activation="softmax")) model.add(keras.layers.Dense(1, activation="linear")) [instruction] | Convert the following deep learning model definition code to use the Keras API. model = Sequential() model.add(Dense(256, activation="relu", input_dim=20)) model.add(Dense(128, activation="sigmoid")) model.add(Dense(64, activation="softmax")) model.add(Dense(1, activation="linear")) [input] |
[output] | #include <iostream> // Function that takes in two integers, multiplies them and then prints the result void multiplyAndPrint(int num1, int num2) { int result = num1 * num2; std::cout << "The result is: " << result << std::endl; } [instruction] | Create a function in C++ that takes in two integers, multiplies them and then prints the result. [input] |
[output] | def linear_search(arr, x): for i in range(len(arr)): if arr[i] == x: return i return -1 [instruction] | Write a code to perform linear search in an array of integers. [input] |
[output] | A dictionary can be used to store student records. The keys in this dictionary will correspond to the student name and the values will be another dictionary that contains the other fields such as 'age', 'major', and 'graduation_year'. [instruction] | Design a data structure that can be used to store student records with the fields 'name', 'age', 'major', and 'graduation_year'. [input] |
[output] | The type of search algorithm used to find the shortest path from two points is called Dijkstra's Algorithm. [instruction] | What type of search algorithm is used to find the shortest path between two points? [input] |
[output] | animal = { 'name': 'Rex', 'age': 10, 'type': 'dog' } [instruction] | Extend the following python code to include a new field 'type' with the value 'dog'. [input] | animal = { 'name': 'Rex', 'age': 10 }
[output] | import xml.etree.ElementTree as ET tree = ET.parse('document.xml') root = tree.getroot() for node in root.findall('node'): name = node.find('name').text print(name) [instruction] | Parse the following XML document and print out the 'name' fields of all the nodes. [input] | <root> <node> <name>Foo</name> <age>25</age> </node> <node> <name>Bar</name> <age>30</age> </node> </root>
[output] | The relational database schema can be designed as follows: Book: - book_id (primary key) - title - subject - author Author: - author_id (primary key) - name - email Book_Author_Relationship: - book_id (foreign key of Book) - author_id (foreign key of Author) [instruction] | Design a relational database schema for a library that stores book information such as title, subject, and author. [input] |
[output] | #include <iostream> using namespace std; int main() { for (int i = 1; i <= 4; i++) { for (int j = 1; j <= i; j++) { cout << j << " "; } cout << endl; } return 0; } [instruction] | Write a C++ program to print the following pattern. 1 1 2 1 2 3 1 2 3 4 [input] |
[output] | def selection_sort(list): # Traverse through all array elements for i in range(len(list)): # Find the minimum element in remaining # unsorted array min_idx = i for j in range(i+1, len(list)): if list[min_idx] > list[j]: [instruction] | Describe a method for sorting a list of integers using selection sort. [input] | list = [3, 6, 8, 9, 5]
[output] | function toggleFontSize(){ let fontSize = document.body.style.fontSize; if(fontSize === "") { document.body.style.fontSize = "2rem"; } else{ document.body.style.fontSize = "" } } [instruction] | Write a JavaScript method to toggle font size on a webpage. [input] |
[output] | function validateForm(form){ let valid = true; for(let i=0; i < form.length; i++){ let field = form[i]; if(field.value.trim() === ''){ valid = false; } } return valid; } [instruction] | Write a JavaScript method for validating a form. [input] |
[output] | def get_day(date): days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] day_index = date.weekday() return days[day_index] print(get_day(date(2020, 10, 13))) [instruction] | Develop a function in Python which prints the name of the day (eg. "Monday") given any date as an argument. [input] | Date: October 13th, 2020
[output] | left, right = '', '' for char in string: if char.isdigit(): left += char else: right += char [instruction] | Given a string consisting of alphanumeric characters, separate it into left and right parts so that the left part contains only digits and the right part contains only letters. [input] | String: Ab243rG
[output] | def find_average(): a = int(input("Enter first number: ")) b = int(input("Enter second number: ")) return (a + b) / 2 [instruction] | Modify the existing code to enable user input so the user can enter their own number and have the average of those two numbers returned. [input] | def find_average(a, b): return (a + b) / 2
[output] | list=1:10 list_squared = list^2 print(list_squared) [instruction] | Develop an R script to print the squares of the first 10 natural numbers. [input] |
[output] | def matrix_addition(mat1, mat2): # check whether two matrices are of same size if(len(mat1) != len(mat2)): return 'Not possible to add matrices' else: # adding elements of mat1 and mat2 result = [[0 for col in range(len(mat1[0]))] for row in range(len(mat1))] [instruction] | Write a code to add two matrices of any size. [input] | [[1, 2, 3], [4, 5, 6]] + [[7, 8, 9], [10, 11, 12]]
[output] | def area_of_circle(radius): """ This function takes a radius as input and returns the area of the circle. Parameters: radius (float): The radius of the circle. Returns: float: The area of the circle. """ return 3.14 * (radius ** 2) [instruction] | Create a function to find the area of a circle by taking the radius as an argument. [input] |