[output] | def decrypt_caesar_cipher(cipher_text): alphabet="abcdefghijklmnopqrstuvwxyz" output="" for char in cipher_text: i=(alphabet.index(char)-3)%26 output+=alphabet[i] return output [instruction] | Write a code to decrypt a given cipher text using the Caesar cipher [input] | cipher_text="dfwlrq"
[output] | <blockquote> </blockquote> [instruction] | Write an HTML tag for a blockquote. [input] |
[output] | function countOccurences(arr){ let count = {}; arr.forEach(function(i) { count[i] = (count[i]||0) + 1;}); return count; } [instruction] | Write a JavaScript function that takes an array and counts the occurence of each element in the array. [input] | [1, 4, 2, 4, 1]
[output] | <html> <head> <title>Text Boxes</title> </head> <body> <form> Name: <input type="text" name="name" /> <br><br> Age: <input type="text" name="age" /> <br><br> <input type="submit" value="Submit"> </form> [instruction] | Create an HTML page that contains two textboxes. The first textbox is for the user to type in their name and the second textbox is for the user to type in their age. [input] |
[output] | 1. Explicitly deallocate any unnecessary memory by using `del`: `del message` 2. Close any open files or resources by using the `with` block for better resource management: ``` with open("file_name","w") as f: # process the file ``` 3. Avoid using dynamic memory allocation where possible. Yo [instruction] | Analyze the code below and suggest three ways to address the memory leak issue. [input] | import os def function(): message = "" while True: message += "a" * 1024
[output] | print(' * ') print(' *** ') print('*****') [instruction] | Output the below tree structure in Python. [input] |
[output] | float [instruction] | Identify the correct data type for the value "37.45". [input] |
[output] | #include <iostream> void print_fibonacci(int n) { int first = 0, second = 1, next; while (first <= n) { std::cout << first << " "; next = first + second; first = second; second = next; } } int main () { int n = 50; print_fibonacci(n); return 0; } [instruction] | Create a function in C++ to print the Fibonacci numbers between 0 and 50. [input] |
[output] | The Naive Bayes classifier is a probabilistic learning model that is based on the Bayes' theorem. It is a supervised learning algorithm that uses prior probabilities and uses it to observe the relationship between the dependent variable and the independent variable. This algorithm assumes that the d [instruction] | Explain how the Naive Bayes classifier works. [input] |
[output] | def sort_by_distinct_characters(strings): strings.sort(key=lambda x: len(set(list(x)))) return strings [instruction] | Write a function that sorts an array of strings in ascending order based on the number of distinct characters in each string. [input] |
[output] | def find_triplet_sum(arr, target): arr.sort() for i in range(0, len(arr)-2): left = i + 1 right = len(arr) - 1 while left < right: curr_sum = arr[i] + arr[left] + arr[right] if curr_sum == target: return True elif [instruction] | Take an array of integers and return true if there is a triplet whose sum is equals to the given target. [input] | arr = [1, 4, 45, 6, 10, -8], target = 16
[output] | def is_prime(num): # form 2 to num-1 for i in range(2, num): # percentage to check, output False if divisible by any number if num % i == 0: return False return True [instruction] | Compile a function that checks if a number is prime. Output true if prime, false if not. [input] |
[output] | def longest_strings(str_arr): longest = 0 strings = [] for string in str_arr: if len(string) > longest: strings = [string] longest = len(string) elif len(string) == longest: strings.append(string) return strings [instruction] | Take an array of strings and return a new array containing only the strings with the longest length. [input] |
[output] | def longest_consecutive_str(s): longest_str = "" cur_str = "" for char in s: if not cur_str or char == cur_str[-1]: cur_str += char else: if len(cur_str) > len(longest_str): longest_str = cur_str cur_str = char if [instruction] | Output the longest consecutive character string in a given string. [input] |
[output] | def transpose(matrix): tr_matrix = [[None for i in range(len(matrix))] for j in range(len(matrix[0]))] for i, row in enumerate(matrix): for j, col in enumerate(row): tr_matrix[j][i] = col return tr_matrix [instruction] | Create a function that takes a matrix (MxN array) and returns the transposed matrix. [input] |
[output] | def filter_by_character(str_arr, char): filtered_arr = [] for string in str_arr: if char in string: filtered_arr.append(string) return filtered_arr [instruction] | Take an array of strings and a character and return an array containing only the strings containing the given character. [input] |
[output] | SELECT * FROM users; [instruction] | Construct an SQL query to read the contents of a table called "users". [input] |
[output] | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My Login Page</title> </head> <body> <form action="/login" method="post"> <label for="username">Username:</label><br> <input type="text" id="us [instruction] | Create a web page with a login form that has 2 input fields. [input] |
[output] | import numpy as np arr = np.random.randint(low=0, high=10, size=10) [instruction] | Using Numpy, create an array of size 10 and fill it with random integer numbers between 0 and 9. [input] |
[output] | import requests r = requests.get('http://www.example.com/page') if r.status_code == 200: data = r.text names = re.findall(r'<span class="name">(.*?)</span>', data) emails = re.findall(r'<span class="email">(.*?)</span>', data) [instruction] | Scrape the results of a web page and extract all the names and emails. [input] |
[output] | def sorting_algorithm(arr): for i in range(len(arr)-1): for j in range(i+1, len(arr)): if arr[i] > arr[j]: arr[i], arr[j] = arr[j], arr[i] return arr # Test arr = [34, 19, 42, -9, 2018, 0, 105] print(sorting_algorithm(arr)) # [-9, 0, 19, 34, 42, 105, 2018 [instruction] | Implement a sorting algorithm which takes an array of integers as input and sorts it in ascending order. [input] | [34, 19, 42, -9, 2018, 0, 105]
[output] | class Computer: def __init__(self, name, model): self.name = name self.model = model def get_name(self): return self.name def get_model(self): return self.model [instruction] | Create a class called "Computer" with two attributes "name" and "model" and two methods "get_name" and "get_model". [input] |
[output] | europe_capitals = { 'France': 'Paris', 'Germany': 'Berlin', 'Russia': 'Moscow', 'Greece': 'Athens', 'Norway': 'Oslo', 'Denmark': 'Copenhagen', 'Italy': 'Rome', 'Poland': 'Warsaw', 'Spain': 'Madrid', 'Sweden': 'Stockholm' } [instruction] | Create a dictionary of all the capital cities of Europe as key-value pairs. [input] |
[output] | import random import string def generate_password(length): char_types = list(string.ascii_lowercase + string.ascii_uppercase + string.digits + string.punctuation) password = [] for _ in range(length): ch = random.choice(char_types) while ch in password: ch = [instruction] | Generate a 10 character random user password with at least one Upper Case letter, one lower case letter, one number, and one special character. [input] |
[output] | for i in range(1, 5): for j in range(1, 5): print(i*j, end="\t") print() # Output 1 2 3 4 2 4 6 8 3 6 9 12 4 8 12 16 [instruction] | Generate a 4 by 4 multiplication table. [input] |
[output] | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My Web Page</title> <style> body { margin: 0; padding: 0; } .top-nav { position: fixed; background-color: #222; [instruction] | Design a web page with a top navigation bar and 2 different color sidebars. [input] |
[output] | list = [2, 7, 11, 15] target = 9 for i in range(0, len(list) - 1): for j in range(i + 1, len(list)): if list[i] + list[j] == target: print('The two numbers in the list whose sum is equal to the target number are %d and %d' %(list[i], list[j])) [instruction] | Given a target number, find two numbers in the list whose sum is equal to the target number. [input] | list = [2, 7, 11, 15], target = 9
[output] | arr = [2, 5, 6, 9, -2, -7, -1] # create an empty list to store the products of all triplets triplets = [] # loop through the array for i in range(len(arr)): for j in range(i+1,len(arr)): for k in range(j+1,len(arr)): # calculate and append the product of each triplet to the [instruction] | Given an array of numbers, find the maximum product of any three numbers in the array. [input] | arr = [2, 5, 6, 9, -2, -7, -1]
[output] | def count_characters(string): '''This function takes a string as argument and returns a dictionary that contains the count of characters in the given string.''' # create an empty dictionary char_count = {} # iterate over the characters and add to dictionary if not already pre [instruction] | Extract a character's count from a given string. [input] | string = "this is a sample string"
[output] | string1 = "Hello " string2 = "World" # use '+' operator for string concatenation result_string = string1 + string2 print("The concatenated string is:", result_string) [instruction] | Concatenate two given strings and return the result. [input] | string1 = "Hello ", string2 = "World"