[output] | def common_elements(lst1, lst2): common = [] for i in range(len(lst1)): if lst1[i] in lst2: common.append(lst1[i]) return common if __name__ == '__main__': list1 = [1, 2, 3, 4, 5] list2 = [2, 3, 4, 5, 6] print(common_elements(list1, list2)) [instruction] | Write a function that takes two lists as parameters, and returns a third list, containing the elements that occur on both the given lists. [input] | list1 = [1, 2, 3, 4, 5] list2 = [2, 3, 4, 5, 6]
[output] | print(max(number_list)) [instruction] | Output the greatest number from a list of numbers. [input] | number_list = [4, 8, 15, 16, 23, 42]
[output] | def divisible_by_10_15(number_list): divisible_numbers = [] for num in number_list: if num % 10 == 0 and num % 15 == 0: divisible_numbers.append(num) return divisible_numbers if __name__ == '__main__': number_list = [10, 15, 20, 25, 30, 35, 40] print(divi [instruction] | Output the numbers which are divisible by both 10 and 15 from a list of numbers. [input] | number_list = [10, 15, 20, 25, 30, 35, 40]
[output] | print(my_string.endswith('ing')) [instruction] | Output true if a givenstring ends with 'ing', false otherwise. [input] | my_string = "I am learning"
[output] | function fetchWeather(city){ const url = `http://api.openweathermap.org/data/2.5/weather?q=${city}&appid=YOUR_API_KEY`; const response = fetch(url) .then(res => res.json()); return response; } [instruction] | Write a JavaScript code to fetch the current weather of any city. [input] |
[output] | SELECT category, MAX(price) FROM orders GROUP BY category; [instruction] | Write a query in SQL that returns the maximum number for each unique category. [input] | TABLE orders order_id INT PK category VARCHAR price INT
[output] | x <- c(1,2,4,5) y <- c(2,4,6,10) cor(x, y) [instruction] | Create an R script to calculate the correlation between two numerical vectors, x and y. [input] | x = c(1, 2, 4, 5) y = c(2, 4, 6, 10)
[output] | int binarySearch (int arr[], int l, int r, int x) { while ( l <= r) { int mid = l + (r-1)/2; if (arr[mid] == x) return mid; if (arr[mid] < x) l = mid + 1; else r = mid - 1; } return -1; } [instruction] | Design an algorithm in C# which searches for a given element in a sorted array. [input] | A = [2, 3, 4, 10, 40] element = 10
[output] | SELECT customer_id, SUM(quantity) FROM orders GROUP BY customer_id ORDER BY SUM(quantity) DESC LIMIT 3; [instruction] | Develop a query in MySQL to find the three customers with the highest number of orders. [input] | TABLE orders order_id INT PK customer_id INT quantity INT
[output] | <html> <head> <title>Table Example</title> </head> <body> <table> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> </tr> <tr> <td>Row 1 Data 1</td> <td>Row 1 Data 2</td> <td>Row 1 Data 3</td> </tr> [instruction] | Draft an HTML page with a table that contains three columns and two rows. [input] |
[output] | function descendingOrder(elements) { elements.sort(function(a,b) { return b - a; }); return elements; } [instruction] | Develop a code in JavaScript to sort an array of integers into descending order. [input] | elements = [9,6,5,1,3]
[output] | double getAverage(int arr[], int size) { int i; float avg; float sum=0.0; for (i = 0; i < size; ++i) { sum += arr[i]; } avg = sum / size; return avg; } [instruction] | Code a function in C that takes an integer array and its size as two arguments and returns the average of these numbers. [input] | array = [1,2,3,4,5] size = 5
[output] | def median_age(ages): ages.sort() mid_index = len(ages)//2 if len(ages)%2 == 0: return (ages[mid_index-1] + ages[mid_index])/2 else: return ages[mid_index] [instruction] | Design an algorithm in Python that takes an array of classmates' age and returns the median age. [input] | ages = [10, 9, 12, 14, 11]
[output] | hist(vector, breaks=bin_size, col="blue', border="white") [instruction] | Create a function in R which creates a histogram to visualize a given vector and set the bin size. [input] | vector = c(2, 3, 5, 6, 12) bin_size = 3
[output] | SELECT item_id, category, MAX(price) FROM items GROUP BY category; [instruction] | Write a query in SQL to list the most expensive item from each category. [input] | TABLE items item_id INT PK category VARCHAR price INT
[output] | class Person { String name; int age; String gender; // constructor public Person(String name, int age, String gender) { this.name = name; this.age = age; this.gender = gender; } } [instruction] | We want to create a constructor for a person class which takes the name, age and gender of the person as input. [input] | name = “Bob” age = 32 gender = “Male”
[output] | if num1 < num2: print("num1 is smaller than num2") elif num1 > num2: print("num1 is greater than num2") else: print("num1 is equal to num2") [instruction] | Write a code to compare two numbers in python [input] | num1= 5 num2 = 7
[output] | nicknames = { 'Frodo': 'Halfling', 'Gandalf': 'Grey Wizard', 'Legolas': 'Prince of Mirkwood' } [instruction] | Create an array of nicknames for characters in the Lord of the Rings [input] | Frodo - Hobbit; Gandalf - Wizard; Legolas - Elf;
[output] | def replace_letters(text, letter): new_text = "" for i, char in enumerate(text): if char == letter: new_text += str(i) else: new_text += char return new_text [instruction] | You are given a string and a letter. Output a new string where the occurances of the given letter are replaced with its index in the given string. [input] | "apple" and "l"
[output] | def count_characters(text, char): count = 0 for c in text: if c == char: count += 1 return count [instruction] | Write a function to count the number of times a given character is found in an input string. [input] | "Hello World" and "l"
[output] | def get_index(text, substring): for i in range(len(text)-len(substring)+1): if text[i:i+len(substring)] == substring: return i return -1 [instruction] | You are given a string and a substring. Output the index of the first occurrence of the substring in the string. [input] | "Hello World" and "Wor"
[output] | String arrayToString(char[] array) { String s = ""; for (char c : array) { s += c; } return s; } [instruction] | Write a Java program to convert a recursively given array of characters to a string. [input] | ['a', 'b', 'c']
[output] | SELECT * FROM table_name ORDER BY gender ASC, age ASC; [instruction] | Write a SQL query to sort a table based on the values in two columns, 'gender' and 'age'. [input] |
[output] | SELECT name, population FROM cities ORDER BY population DESC LIMIT 3; [instruction] | Write a SQL query to find the top 3 most populated cities across all states. [input] |
[output] | const express = require('express'); const app = express(); app.get('/', (req, res) => { res.send('Hello World!'); }); // Server listening on port 3000 const port = 3000; app.listen(port, () => console.log(`Server listening on port ${port}`)); [instruction] | Create a basic REST API in Node.js [input] |
[output] | To deploy a static website on AWS, create an S3 bucket and configure the bucket for static website hosting. Upload the website content to the S3 bucket, then create a CloudFront distribution to redirect requests to the S3 bucket. Finally, configure a DNS record to point to the CloudFront distributio [instruction] | Deploy a static website on AWS [input] |
[output] | PUT and DELETE are the HTTP methods used for updating operations. GET and POST are used for retrieving and submitting data, respectively. [instruction] | Which of the following HTTP methods are used for updating operations? [input] | GET, POST, PUT, DELETE
[output] | <form> <label for="first_name">First Name</label> <input type="text" id="first_name" /> <label for="last_name">Last Name</label> <input type="text" id="last_name" /> <input type="submit" /> </form> [instruction] | Create an HTML form to capture the first name and last name of the user. [input] |
[output] | import numpy as np def calculate_average(arr): return np.mean(arr) print(calculate_average([1.5, 2.3, 3.8, 4.2])) [instruction] | Implement a function in Python to compute the average of an array containing floating-point numbers. [input] | [1.5, 2.3, 3.8, 4.2]
[output] | import datetime start_date = datetime.datetime.strptime("1 March 2020", "%d %B %Y") current_date = datetime.datetime.now() number_of_months = current_date.month - start_date.month print("The employee has been working for {} months".format(number_of_months)) [instruction] | Update this script in Python to print the number of months since an employee started working. [input] | start_date = "1 March 2020"