[output] | def remove_letter(string, letter): output = "" for s in string: if s != letter: output += s return output [instruction] | Given a string, write an algorithm to remove all occurrences of a given letter. [input] | my_string = "Python is a popular programming language" letter = 'o'
[output] | def evaluate_expr(expression): return eval(expression) [instruction] | Create a function that evaluates a mathematical expression stored as a string. [input] | expression = "1+2*3/4"
[output] | #main { font-size: 16px; } [instruction] | Write a CSS code to change the font size of an element with id="main". [input] |
[output] | The error is "NameError: name 'printf' is not defined". To solve the error, remove the second line "printf(message)" as "printf()" is not a valid function. [instruction] | Debug and resolve the error in the following code: [input] | message = "Welcome!" print(message) printf(message)
[output] | The data of the first element in a JSON array can be retrieved using the index "0". For example, if the JSON array is ["apple", "banana", "cherry"], then the data of the first element can be retrieved by "array[0]". It would return the data "apple". [instruction] | How to retrieve the data of the first element in a JSON array? [input] |
[output] | A list of words can be converted into a set by using the built-in "set()" function. For example, if the list is ["apple", "banana", "cherry"], the set converted from this list will look like {"apple", "banana", "cherry"}. [instruction] | How to convert a list of words into a set? [input] |
[output] | A key-value pair in a dictionary can be looped over using the "for" loop with the "items()" method. For example, if the dictionary is {'a': 1, 'b': 2, 'c': 3}, it can be looped over as: for key, value in dictionary.items(): print(key, value) It will print the key-value pairs as: a 1 b 2 c 3 [instruction] | How to loop over a key-value pair in a dictionary? [input] |
[output] | def filter_string_length(strings): """ This function takes in a list of strings and filters out those that are not longer than 5 characters. """ return [s for s in strings if len(s) > 5] list_strings = ["Carrot", "Apple", "Orange", "Banana", "Pear"] filtered_list = filter_string [instruction] | Create a function that filters a list of strings based on their length. [input] | List = ["Carrot", "Apple", "Orange", "Banana", "Pear"]
[output] | def age_calc(date_of_birth): """ This function takes in a date of birth and calculates the age in years and months. """ today = datetime.date.today() age_years = today.year - date_of_birth.year age_months = today.month - date_of_birth.month if age_months < 0: [instruction] | Write a code to calculate the age in years and months given the date of birth. [input] | Date of Birth: 4 June 1998
[output] | def list_augment(int_list): """ This function takes in a list of integers and augments it with zeros after every 4 elements. """ augmented_list = [] for i in range(0, len(int_list), 4): augmented_list.append(int_list[i:i + 4]) augmented_list.append(0) aug [instruction] | Augment an integer list with zeros after every 4 elements. [input] | List = [1,2,3,4,5,6,7,8]
[output] | 3 [instruction] | Compare the two strings and report the index of the first mismatch. [input] | String 1: hello String 2: holla
[output] | Max: 9 Min: -1 [instruction] | Determine the maximum and minimum value of an array. [input] | [3, 6, 9, -1, 2]
[output] | ['The', 'the', 'that'] [instruction] | Perform a search operation to find all the words starting with "th". [input] | Sentence: The big cat ate the small mouse.
[output] | SELECT name, salary FROM employees ORDER BY salary DESC LIMIT 5; [instruction] | Implement a SQL query to find the top 5 highest paid employees. [input] |
[output] | def reverse(num): reversed_num = 0 while num>0: last = num%10 reversed_num = (reversed_num*10)+last num = num//10 return reversed_num num = 123 print("Reverse of", num, "is", reverse(num)) # Output: Reverse of 123 is 321 [instruction] | Develop an algorithm to reverse an integer. [input] | 123
[output] | static void GenerateCombinations(int[] arr, int n) { int[] result = new int[n]; GenerateCombination(arr, 0, 0, result); } static void GenerateCombination(int[] arr, int start, int index, int[] result) { if (index == result.Length) [instruction] | Write a C# function to generate all combinations of length n of a given array. [input] |
[output] | def tree_depth(root): if root is None: return 0 ; else : left_height = tree_depth(root.left) right_height = tree_depth(root.right) if (left_height > right_height): return left_height+1 else: return right_height+1 [instruction] | Develop an algorithm to find the depth in a tree. [input] |
[output] | static bool IsArmstrong(int num) { int origNum = num; int sum = 0; int digits = 0; while (num != 0) { digits++; num /= 10; } num = origNum; while (num != 0) { sum +=Math.Pow(num % 10, digits); num /= 10; } if (sum== origNum) return true; return false; [instruction] | Develop a C# function to check if a given number is Armstrong or not. An Armstrong number is one which is equal to the sum of its digits raised to the power of the number of digits. [input] |
[output] | Yes, lycanthropy is a valid word of English language. [instruction] | Determine if a given word is a valid word of English language. [input] | Word: lycanthropy
[output] | The given sentence belongs to the class 'positive sentiment'. [instruction] | Categorize the given sentence into a specific class. [input] | Sentence: It was a beautiful sunny day.
[output] | def is_similar(list_1, list_2): if len(list_1) != len(list_2): return False list_1.sort() list_2.sort() for i, j in zip(list_1, list_2): if i != j: return False return True [instruction] | Write a function in Python to check if two lists have the same elements regardless of their order. [input] | list1 = ["cat", "dog", "mouse"] list2 = ["mouse", "dog", "cat"]
[output] | SELECT name, COUNT(name) FROM orders GROUP BY name [instruction] | Create a SQL statement to select a list of customer names and the number of orders each customer has made. [input] |
[output] | def cost_calc(products, quantity): total_cost = 0 for i, q in zip(products, quantity): cost = i.cost * q total_cost += cost return total_cost [instruction] | You need to debug this code and ensure that it runs properly. [input] | def cost_calc(product, quantity): total_cost = 0 for i, q in zip(products, quantity): cost = i.cost * q total_cost = total_cost + cost return total_cost:
[output] | .dark-orange { background-color: #EC672B; } [instruction] | Create a CSS rule to display an element with a dark orange background color. [input] |
[output] | import React from 'react'; import { BrowserRouter as Router, Route, Link } from 'react-router-dom'; // Home Component const Home = () => { return( <div> <h1>Home</h1> </div> ); } // About Component const About = () => { return( <div> <h1>About</h1> </div> ); } [instruction] | Create a React app with two routes Home and About with two separate components. [input] |
[output] | void selectionSort(int arr[], int n) { int i, j, min_idx; // One by one move boundary of unsorted subarray for (i = 0; i < n-1; i++) { // Find the minimum element in unsorted array min_idx = i; for (j = i+1; j < n; j++) if (arr[j] [instruction] | Choose a sorting algorithm and write a function in C++ to sort a list of numbers. [input] |
[output] | <style> .container { display: flex; } .column { flex: 1; } .main { flex: 2; } </style> <div class="container"> <div class="column"> </div> <div class="main"> </div> <div class="column"> </div> </div> [instruction] | Create a website layout with three columns and fixed size main section. [input] |
[output] | import java.io.*; import java.util.*; import com.amazonaws.services.lambda.*; import com.google.gson.Gson; import com.amazonaws.services.lambda.runtime.Context; import com.amazonaws.services.lambda.runtime.RequestHandler; import org.json.simple.*; import org.json.simple.JSONObject; public clas [instruction] | Create a clould-based web application in Java to store financial details. [input] |
[output] | # import libraries import pandas as pd from sklearn.model_selection import train_test_split from sklearn.feature_extraction.text import CountVectorizer from sklearn.naive_bayes import MultinomialNB # read in the data data = pd.read_csv('email_data.csv') # split into training and test data X_trai [instruction] | Train a Naive Bayes model in Python to classify emails into spam and non-spam classes. [input] |
[output] | #include <iostream> using namespace std; int main() { // set the array size int n = 5; int arr[n]; // set the first and last element to the same value arr[0] = 5; arr[n-1] = 5; // fill in the other elements for (int i = 1; i < (n-1); i++) arr[i] = 0; [instruction] | Create an array of integers using C++ where the first element is equal to the last element. [input] |