[output] | def is_prime(n): if n == 1: return False for i in range(2, n): if n % i == 0: return False return True def print_primes(): count = 0 number = 2 while(count != 10): if is_prime(number): print(number) count += 1 [instruction] | Modify the code provided so it prints the first 10 prime numbers. [input] | def is_prime(n): if n == 1: return False for i in range(2, n): if n % i == 0: return False return True
[output] | def print_multiplication_table(n): for i in range(1, n+1): for j in range(1, n+1): print(i*j, end=" ") print() print_multiplication_table(n) [instruction] | Design a function that takes in an integer and prints the multiplication table till that input number. [input] |
[output] | def replace_space_with_hyphen(sentence): return sentence.replace(" ", "-") print(replace_space_with_hyphen(sentence)) [instruction] | Create a program that reads a sentence, replaces all spaces with hyphens, and prints the modified sentence. [input] | sentence = "This is a sentence"
[output] | def reverse_words_order(string): words = string.split(' ') words_reversed = words[::-1] return ' '.join(words_reversed) print(reverse_words_order(string)) [instruction] | Design a function to take a string input and reverse the order of its words. [input] | string = "This is a sentence"
[output] | def solve_math_equation(equation): return eval(equation) print(solve_math_equation(equation)) [instruction] | Create a program to solve a math equation given in a string. [input] | equation = "6 + 3*2"
[output] | SELECT * FROM Customers WHERE store_id = 12345 AND purchases_date > DATE_SUB(CURDATE(), INTERVAL 7 DAY) [instruction] | Create a MySQL query to select all customers who have purchased items from a specific store in the last seven days. [input] | store_id = 12345
[output] | SELECT SUM(price) FROM Purchases; [instruction] | Write an SQL query to calculate the sum of all prices of items purchased by customers. [input] |
[output] | <!DOCTYPE html> <html> <head> <title>My Webpage</title> </head> <body> <h1>List of Products</h1> <table> <thead> <tr> <th>Name</th> <th>Price</th> <th>Quantity</th> </t [instruction] | Create an HTML page to display a heading, a table and a button. [input] | headline = “List of Products” table_headers = [“Name”, “Price”, “Quantity”]
[output] | #include <iostream> #include <vector> void InsertElement(std::vector<int> &vec, int element, int index) { vec.insert(vec.begin() + index, element); // Print vector after inserting element std::cout << "Vector elements after insertion: "; for (int i = 0; i < vec.size(); ++i) [instruction] | Write a C++ program to insert an element into a given vector. [input] |
[output] | #include <iostream> int trailing_zeroes(int n) { int cnt = 0; while (n > 0) { if (n % 10 == 0) cnt++; else break; n /= 10; } return cnt; } // Driver code int main() { int num = 102450; std::cout << trailing_zeroes(num); [instruction] | Create a C++ program to count the number of trailing 0s in a given number. [input] |
[output] | public static String getLongestString(String[] strings) { int maxLength = 0; String longestString = null; for (String s: strings) { if (s.length() > maxLength) { maxLength = s.length(); longestString = s; } } return longestString; } [instruction] | Using Java, create a program that takes a list of strings, and returns the longest one. [input] | strings = ["hello", "world", "this", "is", "a", "test"]
[output] | def reverse_string_order(s1, s2): result = "" for i in range(len(s1)): result += s2[i] + s1[i] return result [instruction] | Implement a function which will take two strings as input and reverse their order while maintaining the same character at each index. [input] | s1 = "hello" s2 = "world"
[output] | #include <iostream> using namespace std; int main() { int a = 3; int b = 4; if(a < b) return 0; else return 1; } // fix: making it an if-else statement instead of using the return statements if (a < b) { return 0; } else { return 1; } [instruction] | Find the bug in the following C++ program and suggest a fix. [input] | #include <iostream> using namespace std; int main() { int a = 3; int b = 4; if(a < b) return 0; else return 1; }
[output] | import nltk from sklearn.feature_extraction.text import CountVectorizer from sklearn.model_selection import train_test_split from sklearn.naive_bayes import MultinomialNB # tokenize text def tokenize(text): tokens = nltk.word_tokenize(text) return tokens # build a Bag of Words model countV [instruction] | Train a model to classify text into two categories, positive and negative. [input] |
[output] | The best way to store the above data in a MySQL database is to create three tables: 1. A "Questions" table with the following fields: - id (Primary key) - question 2. An "Answers" table with the following fields: - id (Primary key) - question_id (Foreign key to the "Questions" table) 3. [instruction] | Suggest the best way to store the following data structure in a MySQL database. [input] | [ { "id": 25, "questions": [ { "question_id": 39, "question": "What is the capital of India?" } ] } ]
[output] | We can use Django to create a basic website for a restaurant by following the steps below: 1. Design a template for the website using HTML and CSS 2. Create a Django project with the basic layout as given by the template 3. Create views that will be used to render different pages (eg. home page, m [instruction] | Use Django to create a basic website for a restaurant. [input] |
[output] | public static int convertBase(int num, int fromBase, int toBase) { int result = 0; int power = 1; while (num > 0) { result += (num % toBase) * power; power *= fromBase; num /= toBase; } return result; } [instruction] | Using Java, build a program that will convert a given number from one base to another. [input] |
[output] | function findIndexOfHighestValue(list){ let highest = list[0]; let highestIndex = 0; for (let i=0; i<list.length; i++){ if (list[i] > highest){ highest = list[i]; highestIndex = i; } } return highestIndex; } [instruction] | Create a program in JavaScript that will take a list of numbers and return the first index of the highest value. [input] | list = [1, 2, 5, 4, 4]
[output] | function dedupeArray(arr){ let uniqueArray = []; arr.forEach(item => { if(uniqueArray.indexOf(item) === -1){ uniqueArray.push(item); } }); return uniqueArray; } [instruction] | Use Node.js to create a program which will take an array of strings and remove any duplicate values. [input] |
[output] | We can use Gaussian Mixture Models to detect anomalies in time-series data. This method takes the time-series data as input and trains a model using the data. The model defines a probability distribution for the time-series data, and the anomalies are detected as those data points which have a low p [instruction] | Suggest an algorithm in Python that will detect an anomaly in time-series data. [input] |
[output] | func min(numbers []int) int { min := numbers[0] for _, number := range numbers { if min > number { min = number } } return min } [instruction] | Create a program in Go that will take an array of integers and return the smallest number. [input] |
[output] | /** * Function to extract the domain name from a given URL string * @param {string} url - The URL * @return {string} The domain name */ function extractDomain(url) { var a = document.createElement('a'); a.href = url; // Deconstruct the URL to get the domain return a.hostname; } [instruction] | Given a URL string, create a JavaScript function to extract the domain name. [input] | https://www.example.com
[output] | Using the += operator is more efficient on strings than using a+=b in Java because += operator creates only one string object in memory, whereas a+=b creates a new string every time and requires two string objects. This means that using += operator for strings is faster and uses less memory than usi [instruction] | Why is using the+= operator more efficient than using a+=b on strings in Java? [input] |
[output] | public class Student { private String firstName; private String lastName; private int age; public Student(String firstName, String lastName, int age) { this.firstName = firstName; this.lastName = lastName; this.age = age; } public String get [instruction] | Create a Java class called Student that contains a first name, last name and age. [input] |
[output] | Binary search is an efficient search algorithm for sorted arrays. In Python, the bisect module can be used for binary search. The bisect.bisect() function finds the position of the number in the list or a place for the number if it is not present. The bisect.bisect_left() function does the same, but [instruction] | Explain how to use Binary Search in Python? [input] |
[output] | #Function to check if a number is an Armstrong number def isArmstrong(number): sum = 0 temp = number while temp > 0: digit = temp % 10 sum += digit ** 3 temp //= 10 if number == sum: return True else: return False #Usage number = 9 if(isArmstrong(numb [instruction] | How to check if a given number is an Armstrong number in Python? [input] |
[output] | SELECT * FROM table_name LIMIT 20; [instruction] | Construct an SQL query that retrieves the first 20 rows from a table. [input] |
[output] | text = 'Hello, this is a text' out_text = re.sub('[^a-zA-Z0-9]', '', text) print(out_text) [instruction] | Parse the following text and remove all non-alphanumeric characters [input] | Hello$#@, this is a te*x&t
[output] | Sequence data types in Python include lists, tuples and range objects. [instruction] | Select the Python data types which can store a sequence of items. [input] |
[output] | SELECT * FROM products WHERE price = 10; [instruction] | Write a SQL query to find all records from the table 'products' with a price equal to 10. [input] |