[output] | answer = n if answer % 2 == 0: print('even') elif answer % 2 == 1: print('odd') [instruction] | Edit the code so that it produces the desired output. [input] | answer = n if answer % 2 == 0: print('even') else: print('odd') Output:"
[output] | def isReverse(string_1, string_2): if len(string_1) != len(string_2): return False for i in range(len(string_1)): if string_1[i] != string_2[len(string_2)-i-1]: return False return True [instruction] | Write a function that takes two strings and returns True if one of the strings is the other string reversed. [input] | string_1 = "abcde" string_2 = "edcba"
[output] | def longestSubstring(s): length = len(s) longest_string = 0 i = 0 while (i < length): # Store the last index of the current character last_char_index = -1 string_set = set() current_string = 0 for j in range(i, lengt [instruction] | Write a code that returns the longest substring of the given string without repeating characters. [input] | string = "abcabcbb"
[output] | This code produces a TypeError as it is attempting to add an integer to a string. [instruction] | Identify what type of error the code has [input] | x = 10 y = "10" z = x + y
[output] | def deleteNode(head, del): # If the node to be deleted is the head node if head.data == del: head = head.next return head # Find previous node of the node to be deleted previous = head while previous.next and previous.next.data != del: previou [instruction] | Implement an algorithm to delete a node in a singly linked list, given only access to the node. [input] | head = [4, 5, 1, 9] del = 5
[output] | #Split the string into a list of integers numbers = [int(x) for x in string.split(',')] #Iterate through the list, if the integer is even, print it for number in numbers: if number % 2 == 0: print(number) [instruction] | Given a string containing a comma-separated list of integers, write code to print all the even numbers. [input] | string = "23, 2, 5, 16, 1, 9, 8"
[output] | def printString(string, number): for i in range(number): print(string) printString(string, number) [instruction] | Create a function that takes two parameters, a string and an integer, and prints the string the given number of times. [input] | string = "Hello" number = 3
[output] | lst = [[1, 2], [3, 4], [5, 6]] flattened = [item for sublist in lst for item in sublist] print(flattened) [instruction] | Given a list of lists, generate a single flattened list. [input] | lst = [[1, 2], [3, 4], [5, 6]]
[output] | SELECT word, COUNT(*) AS occurrence FROM article GROUP BY word ORDER BY occurrence DESC LIMIT 10; [instruction] | Write an SQL query that displays a table of the ten most commonly used words in the given article. [input] | Today, I climbed the tallest mountain in the world. It was an incredible experience with stunning views and a sense of accomplishment at the top.
[output] | #include <stdio.h> int main() { int num; printf("Enter a number: "); scanf("%d", &num); num += 10; printf("The result is %d", num); return 0; } [instruction] | Create a C program that asks for a user input, adds 10 to the value, and prints the result. [input] |
[output] | x = 10 if x > 0: print("x is positive") [instruction] | Translate the following JavaScript code into Python. [input] | let x = 10; if(x > 0){ console.log("x is positive"); }
[output] | def reverse(head): prev = None curr = head while curr is not None: next_node = curr.next curr.next = prev prev = curr curr = next_node head = prev return head [instruction] | Write a function to reverse a linked list in O(n) time complexity. [input] |
[output] | class Car { private String name; private String model; private int year; private double price; //constructor to initialize Car object public Car(String name, String model, int year, double price) { this.name = name; this.model = model; this.year = year; this.price = price; } / [instruction] | Design a Java class for a Car which has the following attributes: name, model, year, and price. [input] |
[output] | function reverseArray(arr) { return arr.reverse(); } [instruction] | Create a Javascript function which takes an array as an argument and returns an array with the elements in reverse order. [input] | [1, 2, 3, 4, 5]
[output] | @Configuration public class StringBeanProvider { @Bean public String provideString() { return "Hello World!"; } } [instruction] | Design a Spring Boot class that provides a bean of type String to the application. [input] |
[output] | import imdb # create an instance of the IMDb class ia = imdb.IMDb() # get the movie movie = ia.get_movie('tt0111161') # The Shawshank Redemption # get the rating rating = movie['rating'] # print the rating print(f"Rating for the movie 'The Shawshank Redemption': {rating}") [instruction] | Tell me how to print an IMDB movie rating using Python [input] |
[output] | FUNCTION isPalindrome(arr[], size) START i <- 0 j <- size-1 WHILE i < j DO IF arr[i] != arr[j] RETURN false END IF i <- i + 1 j <- j - 1 END WHILE RETURN true END [instruction] | Generate a pseudocode for an algorithm to check if an array is a palindrome. [input] |
[output] | The important data types in Python are integers, floats, strings, booleans, lists, tuples, dictionaries and sets. [instruction] | Name some of the important data types in Python. [input] |
[output] | all_same = len(list) > 0 and all(x == list[0] for x in list) [instruction] | Create a condition statement to check if all elements in a list are the same. [input] |
[output] | i = 0 while i < len(arr): print(arr[i]) i += 1 [instruction] | Create a while loop to print all elements of an array. [input] | arr = [1, 2, 3, 4, 5]
[output] | for key, val in d.items(): print(f"{key} : {val}") [instruction] | Create a loop to go through all elements of a dictionary. [input] | d = {'name':'John', 'age': 27, 'job': 'Programmer'}
[output] | public class Customer{ private int age; private String name; public Customer(int age, String name) { this.age = age; this.name = name; } public int getAge() { return age; } public String getName() { return name; } } public class Age [instruction] | Design a data structure in Java to store and sort a list of customers by their age. [input] |
[output] | int[] input_arr = { 3, 4, 5, 7, 8 }; int[] output_arr = new int[input_arr.length]; for (int i = 0; i < input_arr.length; i++) { output_arr[i] = input_arr[input_arr.length - 1 - i]; } [instruction] | Write code to produce the output mentioned. [input] | Input Array: [3, 4, 5, 7, 8] Output Array: [7, 8, 5, 4, 3]
[output] | #include <iostream> class Circle { private: double radius; public: Circle(double r) { radius = r; } double getRadius() { return radius; } }; [instruction] | Create a class in C++ for a circle which includes radius as a member variable. [input] |
[output] | lst = [3, 8, 9] for i in lst: print(str(i)) # Output 3 8 9 [instruction] | Edit the given code in Python to produce the desired output. [input] | lst = [3, 8, 9] for i in lst: print(i) Expected Output: 3 8 9
[output] | SELECT * FROM Employees WHERE salary > 30000; [instruction] | Write a SQL query to select all employee records with salary greater than 30000. [input] | Employees Table id | name | age | salary ------------------------ 1 | John | 20 | 25000 2 | Nancy | 27 | 35000 3 | David | 30 | 40000 4 | Mike | 36 | 31000
[output] | def sum_from_string(str) array = str.scan(/\d+/).map(&:to_i) sum = array[0] + array[1] return sum end sum_from_string("The sum of 4 and 8 is 12") # Output: 12 [instruction] | In Ruby, write a method to find the sum of two numbers from the given string. [input] | String: “The sum of 4 and 8 is 12”
[output] | SELECT salary FROM Employee WHERE name = 'Bob'; [instruction] | Write a query in MySQL to find the particular employee's salary from an employee table. [input] | Employee table name | age | salary Bob | 20 | 20000 John | 45 | 27000 Tim | 23 | 35000
[output] | <div style="width: 400px; margin: 0 auto; text-align: center;"></div> [instruction] | Repair the given HTML code to display a ‘div’ element centered on the page with a width of 400px. [input] | <div style="width: 400px; margin: 0 auto;"></div>
[output] | .button { text-size: 18px; border: 3px solid blue; } [instruction] | Write a custom CSS class to add a 3px solid blue border around a button with text size as 18px. [input] |