[output] | if <condition>: print("Condition is satisfied") [instruction] | Replace the "TODO" comment in the given code with appropriate code. [input] | if <condition>: # TODO
[output] | def fib(n): a = 0 b = 1 if n == 0: return a elif n == 1: return b else: for i in range(2,n): c = a + b a = b b = c return b [instruction] | Create a algorithm to calculate the fibonacci number of nth term. [input] |
[output] | The purpose of the Java virtual machine (JVM) is to provide a runtime environment for Java applications, in which programs are able to run independently of the underlying operating system. It is responsible for providing a secure and portable environment for the Java program's execution, as well as [instruction] | What is the purpose of Java virtual machine? [input] |
[output] | INSERT INTO customers (name) VALUES ('John Doe'); [instruction] | Construct a SQL query to add a new row to a column in a table [input] | Table Name: "customers" Column Name: "name" New row: "John Doe"
[output] | function filterArray(array){ let newArray = []; for(let i=0; i<array.length; i++){ if(array[i] >= 0){ newArray.push(array[i]); } } return newArray; } [instruction] | Create an array filtering function using JavaScript [input] |
[output] | Public Sub PrintArray(arr() As Integer) For i = 0 To arr.Length - 1 Console.WriteLine(arr(i)) Next End Sub [instruction] | Create a Visual Basic function to print the contents of an array. [input] |
[output] | The purpose of a library in software development is to provide a collection of related functions and data structures that can be used by a program. Libraries are used to simplify or abstract away the details of how a particular operation is implemented or offer prepackaged functionality. Libraries o [instruction] | What is the purpose of a library in software development? [input] |
[output] | def unique_4_digit_combos(): # initialize a set to store the combinations combos = set() # loop through integers between 0000 and 9999 for i in range(10000): # convert integer to string digits = str(i).zfill(4) # check if not repeated characters if le [instruction] | Generate code to print all unique 4 digit combos [input] |
[output] | def cost(x, price): return x*price cost(5, 2.00) # returns 10.00 [instruction] | Write a function to calculate the cost of purchasing X items at a given cost [input] | X = 5 and Cost per item= 2.00
[output] | def linear_interpolation(x1, y1, x2, y2): # slope m = (y2 - y1) / (x2 - x1) # intercept c = y2 - (m * x2) return m, c [instruction] | Develop a method to achieve the linear interpolation between two given points [input] |
[output] | def print_spiral(matrix): # matrix is an 2D array row_start = 0 row_end = len(matrix)-1 col_start = 0 col_end = len(matrix[0])-1 while row_start <= row_end and col_start <= col_end: # print top row for i in range(col_start, col_end+1): print(mat [instruction] | Generate code for printing a given 2D matrix in spiral order [input] | matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
[output] | import tensorflow as tf # create the model model = tf.keras.models.Sequential() # add layers to the model model.add(tf.keras.layers.Dense(128, activation='relu')) model.add(tf.keras.layers.Dense(64, activation='relu')) model.add(tf.keras.layers.Dense(32, activation='relu')) model.add(tf.keras.laye [instruction] | Create a TensorFlow program to implement a multi-layer neural network [input] |
[output] | # create a priority queue # score will be the priority and name will be stored as data import queue scores = queue.PriorityQueue(maxsize=5) def add_score(score, name): if scores.full(): min_score = scores.get() if min_score[0] < score: scores.put((score, name)) [instruction] | Create a data structure to store the 5 highest scores of a given game [input] |
[output] | def storeDataIn2DArray(data): rowLength = len(data[0]) columnLength = len(data) twoDArray = [] for row in range(rowLength): twoDArrayRow = [] for column in range(columnLength): twoDArrayRow.append(data[column][row]) twoDArray.append(twoDArrayR [instruction] | Write an algorithm to store the data in a 2D array. [input] | [[1,2,3,4], [5,6,7,8], [9,10,11,12], [13,14,15,16]]
[output] | def printPreOrder(root): if root != None: print(root.data, end=" ") printPreOrder(root.left) printPreOrder(root.right) [instruction] | Create a function to print the contents of a binary tree in pre-order format. [input] |
[output] | def find_largest(lst): largest_number = lst[0] for num in lst: if num > largest_number: largest_number = num return largest_number [instruction] | Alter the following code to create a function called "find_largest" to find the largest number in a given list. [input] | [9, 11, 7, 16, 20]
[output] | #!/bin/bash # Retrieve the IP address of a given domain name DOMAIN="$1" if [[ -n "$DOMAIN" ]] ; then IP_ADDRESS=$(getent ahostsv4 "$DOMAIN" | tail -1 | cut -d" " -f1) echo -e "The IP address of $DOMAIN is $IP_ADDRESS" else echo -e "Please enter a domain name \nExample: www.example.co [instruction] | Create a bash script to retrieve the IP address of a given domain name. [input] |
[output] | dic = {"Name": "John", "Age": 20, "Country": "USA"} for key, value in dic.items(): print(key + " : " + str(value)) [instruction] | Write a python code to print every key and its corresponding value in a dictionary. [input] | {"Name": "John", "Age": 20, "Country": "USA"}
[output] | def detectLoop(head): slow_p = head fast_p = head while (slow_p and fast_p and fast_p.next): slow_p = slow_p.next fast_p = fast_p.next.next if slow_p == fast_p: return 1 return 0 [instruction] | Alter the following code to detect a loop in a linked list [input] |
[output] | function convert24HourFormatTo12HourFormat(hours) { if (hours > 12) { return (hours - 12) + "PM"; } else if (hours == 12) { return hours + "PM"; } else if (hours == 0) { return 12 + "AM"; } else { return hours + "AM"; } } [instruction] | Create a function in Javascript to convert hour in 24-hours format to hour in 12-hours format. [input] | 14
[output] | def serializeBinaryTree(root): if root == None: return "#" serializedTree = "" serializedTree += str(root.val) + ',' serializedTree += serializeBinaryTree(root.left) + ',' serializedTree += serializeBinaryTree(root.right) return serializedTree [instruction] | Suggest a way to serialize a binary tree in python. [input] |
[output] | def getLastElement(head): # Base case if head == None: return None # If list is not empty, traverse # to the last node start = head while (start.next != None): start = start.next # return last element return start [instruction] | Alter the code to return the last element of a linked list. [input] |
[output] | board = [['X', 'O', 'X'], ['O', 'X', 'O'], ['X', 'X', 'O']] for row in board: for cell in row: print(cell, end=" ") print() [instruction] | Suggest a python code to print a 2D board with 'X' and 'O'. [input] | [['X', 'O', 'X'], ['O', 'X', 'O'], ['X', 'X', 'O']]
[output] | The sum of the integers in the array is 15. [instruction] | Compute the sum of the integers in the given array. [input] | Integers in the array: [1, 2, 3, 4, 5]
[output] | for i in range(10): print("Goodbye") [instruction] | How would you print "Goodbye" ten times in Python? [input] |
[output] | The sorted list is [1, 2, 3, 4, 5]. [instruction] | Sort the list ```[5, 3, 1, 4, 2]``` numerically. [input] |
[output] | class Node: def __init__(self, data): self.data = data self.next = None class LinkedList: def __init__(self): self.head = None list = [10, 20, 30] llist = LinkedList() llist.head = Node(list[0]) temp = llist.head for i in range(1, len(list)): temp.next = Node(list[i]) temp = temp. [instruction] | Create a linked list to store the values ```[10, 20, 30]```. [input] |
[output] | You would use a String data type to store the title of a book. [instruction] | What data type would you use to store the title of a book? [input] |
[output] | def calculate_area(self): return (self.base * self.height) / 2 [instruction] | Create an object method to calculate the area of a triangle in Python. [input] |
[output] | You can cast a float to an integer in C++ using the (int) operator. [instruction] | How would you cast a float to an integer in C++? [input] |