[output] | person = { 'name': 'John Doe', 'age': 34, 'gender': 'Male' } [instruction] | Create an object in Python which will store the following information [input] | Name: John Doe Age: 34 Gender: Male
[output] | for i in range(10): print(i+1) [instruction] | Make changes to the following code so it prints out the range from 0 to 9. [input] | for i in range(10): print(i)
[output] | while True: print("Hello") if condition is met: break [instruction] | Make changes to the following code to include a 'break' statement. [input] | while True: print("Hello")
[output] | The main difference between a 'for' loop and a 'while' loop is that a 'for' loop is used to iterate through a set of numbers, whereas a 'while' loop is used to continue executing a code block until the condition becomes false. A 'for' loop is generally used when there is an established number of ite [instruction] | Explain the difference between the 'for' and 'while' loop [input] |
[output] | string chs = "abcdefghijklmnopqrstuvwxyz"; string RandomString = ""; Random rd = new Random(); for (int i = 0; i < 5; i++) { RandomString += chs[rd.Next(0,26)]; } Console.WriteLine(RandomString); [instruction] | Generate a correct C# code to randomly generate a 5 letter string [input] |
[output] | SELECT employee_id, name FROM Employee; [instruction] | Generate an SQL statement to select employee Id and name from the 'Employee' table [input] |
[output] | List list = new ArrayList<>(); [instruction] | Generate a Java code snippet for declaring an empty list [input] |
[output] | $string = "Hello World!"; echo strlen($string); [instruction] | Create a PHP code snippet to determine the length of a string [input] |
[output] | if (num >= 10 && num <= 20) { // code } [instruction] | Create an expression statement in Java to check if a given number is between 10 and 20 [input] | 15
[output] | #include <cstdio> #include <vector> using namespace std; class Matrix { private: vector<vector<int>> matrix; int rows, cols; public: // Default constructor Matrix(int r = 0, int c = 0); // Parametrized constructor Matrix( [instruction] | Construct a C++ class to store a matrix. [input] |
[output] | Array.sort() print(Array) # prints [2,5,8] [instruction] | Draft a Python code to sort an array containing 3 integers in ascending order. [input] | Array=[5,2,8]
[output] | The code can be executed by calling the function greeting: greeting() #prints "Hello World!" [instruction] | How can you execute the following Python code to get the output printed? [input] | def greeting(): print("Hello World!")
[output] | { "name": "John", "age": 42, "address": { "street": "123 Main Street", "city": "San Francisco", "state": "CA" } } [instruction] | Provide an example of a JSON structure which has the same data as the following Python dictionary. [input] | user_info = { 'name': 'John', 'age': 42, 'address': { 'street': '123 Main Street', 'city': 'San Francisco', 'state': 'CA' } }
[output] | def swap_dict_keys(d): return {v: k for k, v in d.items()} [instruction] | Create a Python function to swap key-value pairs in a dictionary. [input] |
[output] | <form action=""> First Name: <input type="text" name="first_name" required><br> Last Name: <input type="text" name="last_name" required><br> Phone Number: <input type="text" name="phone_number" required><br> Email Address: <input type="email" name="email_address" required><br> <i [instruction] | Construct an HTML form to get user input for first name, last name, phone number and email address. [input] |
[output] | function reverseString(str) { return str.split('').reverse().join(''); } [instruction] | Construct a JavaScript function to reverse the characters of a string. [input] |
[output] | { "film": { "title": "The Godfather", "genre": "Drama", "year": 1972 } } [instruction] | Complete the JSON structure with correct syntax to store the following Film object. [input] | Film - title: The Godfather - genre: Drama - year: 1972
[output] | def longest_common_substring(str1, str2): # keep track of the longest substring longest_substring = "" # iterate over each character in the first string for i in range(len(str1)): # iterate over each sub sequence of the first string for j in range(i+1, len(str1)+ [instruction] | Create a function to take two input strings and return the longest common substring. [input] | Input 1: ababcd Input 2: abxyz
[output] | def function_1(): param1 = input("Enter parameter: ") print("The parameter is: " + param1) The issue with the code is that it has a misspelling in the function name (fucntion_1 instead of function_1). The input prompt also lacks a space after "Enter-parameter" and a colon should be used at [instruction] | Identify errors in the following code and suggest corrections. [input] | def fucntion_1(): param1 = input("enter-parameter") print("The parameter is:" + param1)
[output] | def insertion_sort(nums): # iterate over the array for i in range(1, len(nums)): j = i-1 # hold element to be inserted temp = nums[i] # shift elements right if greater than element to be inserted while nums[j] > temp and j >= 0: nums[j+1] [instruction] | Given an array of integers, implement insertion sort to sort the array. [input] | [1, 4, 2, 7, 5]
[output] | def partition(nums, low, high): i = low-1 # set pivot as last element in array pivot = nums[high] for j in range(low, high): # if element is smaller than pivot, increment i and swap elements if nums[j] < pivot: i += 1 nums[i], nums[j] = nu [instruction] | Implement quick sort to sort the given array of integers. [input] | [9, 5, 8, 1, 3, 6, 7]
[output] | def compare_strings(string1, string2): i = 0 length = min(len(string1), len(string2)) while i < length: if string1[i] < string2[i]: return 'smaller' elif string1[i] > string2[i]: return 'bigger' i += 1 if len(string1) > len(string [instruction] | Compare two strings and return "bigger", "smaller" or "equal" depending on the lexicographical order. [input] | string1 = "zebra" string2 = "zeal"
[output] | def volume_of_cuboid(length, width, height): volume = length * width * height return volume [instruction] | Calculate the volume of a cuboid given the edges. [input] | Length = 4 Width = 5 Height = 2
[output] | def highest_priced_plan(plans): max_price = 0 max_name = "" for plan in plans: if plan["price"] > max_price: max_price = plan["price"] max_name = plan["name"] return max_name [instruction] | Identify the highest pricing plan from the given list. [input] | plans = [{"name": "Basic", "price": 10}, {"name": "Pro", "price": 20}, {"name": "Premium", "price": 30} ]
[output] | arr = [7, 8, 2, 9, 4] max_val = 0 for num in arr: if num > max_val: max_val = num print(max_val) # Outputs 9 [instruction] | Edit the following code to print out the maximum value from an array of numbers. [input] | [7, 8, 2, 9, 4]
[output] | arr = [3.2, 8.5, 1.6, 6.3] max_val = arr[0] min_val = arr[0] for num in arr: if num > max_val: max_val = num if num < min_val: min_val = num print("Max:", max_val) # Outputs 8.5 print("Min:", min_val) # Outputs 1.6 [instruction] | Create a program that reads an array of numbers and prints the maximum and minimum values. [input] | [3.2, 8.5, 1.6, 6.3]
[output] | def is_pangram(s): s = s.lower() alphabet = "abcdefghijklmnopqrstuvwxyz" for letter in alphabet: if letter not in s: return False return True [instruction] | Construct a function to check if a string is a pangram. [input] |
[output] | public class Rectangle { int length, width; // Constructor public Rectangle(int length, int width) { this.length = length; this.width = width; } public int getPerimeter() { // Calculate perimeter return 2*(length + width); [instruction] | Write a class in Java to calculate the perimeter and area of a rectangle. [input] |
[output] | def binomial_coefficients(n): coefficients = [] for i in range(n+1): coefficients.append(int(math.factorial(n) / (math.factorial(i)*math.factorial(n-i)))) return coefficients # Usage: print(binomial_coefficients(7)) # Outputs [1,7,21,35,35,21,7,1] [instruction] | Construct an algorithm to print out the binomial coefficients of a given number n. [input] |
[output] | def intersection(list_a, list_b): return [element for element in list_a if element in list_b] [instruction] | Write a function in Python that should take two lists and return the intersection. [input] | list_a = [1, 2, 3, 4, 5] list_b = [2, 5, 7, 10]