[output] | def is_uppercase(char): if (char >= 'A' and char <= 'Z'): return True else: return False [instruction] | Construct a code to detect if a character is an uppercase letter or not. [input] |
[output] | import re def match_strings(string1, string2): if re.search(string1, string2): print("Match Found") else: print('No Match Found') [instruction] | Use regular expression to match two strings. [input] |
[output] | def print_pyramid(height): for row in range(1, height + 1): for col in range(1, row + 1): print('*', end=" ") print('\n') [instruction] | Generate a code to create a Pyramid of stars with the given height. [input] |
[output] | def greatestCommonFactor(num1, num2): while num2 != 0: temp = num2 num2 = num1 % num2 num1 = temp return num1 gcf = greatestCommonFactor(8, 32) print(gcf) # Output: 8 [instruction] | Implement an algorithm with the input that calculates the greatest common factor of two numbers. [input] | 8, 32
[output] | SELECT * FROM Employee WHERE id = '5'; [instruction] | Construct a SQL command that selects a row from a table by its ID. [input] | table name: Employee
[output] | public class Point { int x; int y; @Override public boolean equals(Object obj) { if (obj instanceof Point) { Point other = (Point) obj; return x == other.x && y == other.y; } return false; } } [instruction] | Override the equals method for a Java class named Point. [input] | class Point { int x; int y; }
[output] | The big-O complexity of a binary search Algorithm is O(log n). This is because the algorithm halves the input size with every iteration, so it only takes log n iterations to finish. [instruction] | Provide the big-O complexity for a binary search Algorithm. [input] |
[output] | def printIndex(testArray, index): print(testArray[index]) testArray = [1, 2, 3, 4, 5] index = 2 printIndex(testArray, index) # Output: 3 [instruction] | Write a function to print the value at a given index in a given Array. [input] | testArray = [1, 2, 3, 4, 5] index = 2
[output] | SELECT SUM(amount) FROM Purchases; [instruction] | Construct a SQL query to get the sum of all the purchased item from a given table. [input] | table name: Purchases
[output] | def swap(x, y): temp = x x = y y = temp x = 10 y = 5 swap(x, y) print("x =", x, "y =", y) # Output: x = 5 y = 10 [instruction] | Write a function in Python that takes two numbers and swaps the values of the two numbers. [input] |
[output] | addi $t1, $zero, 10 #store num1 in $t1 addi $t2, $zero, 15 #store num2 in $t2 add $t0, $t1, $t2 #add num1 and num2 and store result in $t0 sw $t0, ($memory address) #store result in specified memory address [instruction] | Write a MIPS code that adds two numbers and stores the result in a given memory address. [input] | num1 = 10 num2 = 15 memory address = $t0
[output] | SELECT e1.name AS Employee, e2.name AS Manager, e1.salary AS Employee_Salary, e2.salary AS Manager_Salary FROM employee e1 JOIN employee e2 ON e1.managerid = e2.employeeid WHERE e1.salary > e2.salary; [instruction] | Write an SQL Query to print a list of all employees who have a higher salary than their managers. [input] |
[output] | // Delete user with user_id 10 from table details function deleteRecord($table, $key, $value) { $query = "DELETE FROM $table WHERE $key = ?"; $conn = connectToDatabase(); if($conn->prepare($query)->execute([$value])) { return true; } else { return false; } } [instruction] | Write a PHP function to delete a record from a database table. [input] | Table Name: details Key: user_id value : 10
[output] | html { border: 3px solid black; } [instruction] | Write a CSS style to give a border of 3 pixels to the HTML element. [input] |
[output] | func sumUpToNumber(number: Int) -> Int { var sum = 0 for i in 1...number { sum += i } return sum } let sum = sumUpToNumber(number: 1000) print(sum) [instruction] | Write Swift code to get the sum of all the numbers from 1 to 1000. [input] |
[output] | def delete_duplicates(arr) arr.uniq end arr = [1,2,2,3,3,4,5] new_arr = delete_duplicates(arr) p new_arr # => [1, 2, 3, 4, 5] [instruction] | Write a Ruby script to delete duplicates from an array. [input] | [1,2,2,3,3,4,5]
[output] | """ Build a web scraper to store titles and content of article links from a given website """ import requests from bs4 import BeautifulSoup def scrape_website(url): response = requests.get(url) data = response.text soup = BeautifulSoup(data) titles = [] contents = [] for [instruction] | Build a web scraper that stores the main titles and content of article links from a given website. [input] | Website: https://www.techvoice.org/
[output] | def parse_ip_address(ip_string): ip_list = ip_string.split(".") ip_str = "".join(ip_list) return ip_str if __name__ == '__main__': ip_str = parse_ip_address("192.168.137.8") print(ip_str) [instruction] | Create the following function that parses a valid IP address from a string and returns the address string without delimiters and periods. [input] | String = ‘192.168.137.8’
[output] | def format_phone_number(number): parts = number.split('-') digits = [] for part in parts: for char in part: if char.isdigit(): digits.append(char) return '+1' + ''.join(digits) if __name__ == '__main__': number = '(123) 456-7890' canon_num [instruction] | Create a function to format a given phone number “(123) 456-7890” and output a string with canonical format of “+11234567890”. [input] | Phone number: (123) 456-7890
[output] | SELECT MAX(myattribute), MIN(myattribute) FROM mytable [instruction] | Produce a SQL command that retrieves the maximum and minimum values of an attribute from a table. [input] | Table name = 'mytable' Attribute name = 'myattribute'
[output] | set_a = set([1, 2, 3, 4]) set_b = set([2, 4, 6, 8]) intersection = set_a.intersection(set_b) # intersection is the set {2, 4} [instruction] | Create two sets and find the intersection between them. [input] | Set A: [1, 2, 3, 4] Set B: [2, 4, 6, 8]
[output] | Node* reverse(Node* head) { Node* current = head; Node* prev = NULL; Node* next = NULL; if (current == NULL) return NULL; while (current != NULL) { next = current->next; current->next = prev; prev = current; current = next; [instruction] | Given a single linked list, reverse it in place. [input] | Head -> 1 -> 2 -> 3 -> 4 -> 5 -> None
[output] | import pandas as pd df = pd.DataFrame({'Country':['United States', 'Canada', 'United Kingdom', 'United States'], 'State':['New York', 'Ontario', 'London', 'California']}) count = df[df['Country'] == 'United States'].shape[0] print(count) # Output: 2 [instruction] | Using Pandas, count how many rows have a value of "United States" in the "Country" column. [input] | Data: Country State United States New York Canada Ontario United Kingdom London United States California
[output] | key_list = list(dict.keys()) # Output: ['Name', 'Age', 'Gender'] [instruction] | Extract a list of all the keys from a given dictionary. [input] | dict = {'Name': 'John', 'Age': 10, 'Gender': 'Male'}
[output] | import requests url = 'http://example.com' data = {"Name": "John", "Gender": "Male", "Age": 10} requests.post(url, data=data) [instruction] | Using the requests library, post a JSON object to a specified URL. [input] | URL: http://example.com JSON object: {"Name": "John", "Gender": "Male", "Age": 10}
[output] | import requests url = 'http://example.com' response = requests.get(url) data = response.json() [instruction] | Use the requests library to make an API call and return the response as JSON [input] | url = http://example.com
[output] | import re regex = '^\d{10}$' [instruction] | Create a regular expression to match phone numbers in the following format: 0000000000 [input] |
[output] | List1 = list(set(List1)) # Output: List1 = [1, 2, 3, 4] [instruction] | Given an array of positive integers, remove all the duplicates. [input] | List1 = [1, 2, 3, 3, 4, 4, 2]
[output] | def build_even_dict(numbers): even_dict = {key: value for key, value in enumerate(numbers) if value % 2 == 0} return even_dict [instruction] | Create a method to build a dictionary that contains all even numbers from the given list. [input] | [2, 3, 7, 8, 10, 11]
[output] | even_array = [i for i in [43, 55, 12, 23, 44] if i % 2 == 0] [instruction] | Make an array containing all elements of the given list that are even. [input] | [43,55,12,23,44]