[output] | for(let i = 0; i < names.length; i++) { console.log("Hello, my name is " + names[i] + ".") } [instruction] | Create a loop in JavaScript to iterate through all names in an array and print them in a sentence. [input] | names = ["John", "Jack", "Jane", "Jill"]
[output] | def avg(numbers): sum = 0 for num in numbers: sum += num return sum/len(numbers) average = avg([2, 4, 8, 5]) print(average) [instruction] | Develop an algorithm in Python to find the average of four numbers. [input] | [2, 4, 8, 5]
[output] | [ { "Name": "John", "Age": 23, "Country": "USA" }, { "Name": "Jack", "Age": 25, "Country": "Canada" }, { "Name": "Jane", "Age": 20, "Country": "Australia" } ] [instruction] | Convert the following HTML table into a valid JSON format. [input] | <table> <tr> <th>Name</th> <th>Age</th> <th>Country</th> </tr> <tr> <td>John</td> <td>23</td> <td>USA</td> </tr> <tr> <td>Jack</td> <td>25</td> <td>Canada</td> </tr> <tr> <td>Jane</td> <td>20</td> <td>Australia</td> </tr> </table>
[output] | let name = prompt("What is your name?"); console.log(`Hello ${name}, how are you doing today?`); [instruction] | Write a basic JavaScript program to request a user's name and display a greeting message with the user's name. [input] |
[output] | def CtoF(x): F = (9/5 * x) + 32 return F [instruction] | Modify the code to convert any temperature from Celsius to Fahrenheit [input] | def CtoF(x): #TODO
[output] | def switch_list(mylist): for i in range(0, len(mylist), 2): temp = mylist[i] mylist[i] = mylist[i + 1] mylist[i + 1] = temp return mylist [instruction] | Write a function that switches the odd elements and the even elements in a list [input] | def switch_list(mylist): #TODO
[output] | def join_strings(string1, string2): return string1 + string2 [instruction] | Create a function that join two strings into one [input] |
[output] | def remove_all_strings(myList): myList.clear() return myList [instruction] | Given a list of strings, remove all strings in the list [input] | myList = ["item1", "item2", "item3"]
[output] | def change(test): if test==1: return "One" elif test==2: return "Two" elif test==3: return "Three" else: return "Not Found" [instruction] | Update the code to return a different string depending on the value of the variable test [input] | var test = 3 def change(test): #TODO
[output] | def even_odd(number): if number % 2 == 0: return "even" else: return "odd" [instruction] | Edit the code to add an if statement that returns the string "even" if the value of the variable is even, or the string "odd" if the value of the variable is odd. [input] | var number = 5 def even_odd(number): #TODO
[output] | The selection sort algorithm will have a complexity of O(n^2). The bubble sort algorithm will also have a complexity of O(n^2). [instruction] | What type of complexity will the following two sorting algorithms have? [input] | selection sort: O(n^2) bubble sort: O(n^2)
[output] | def min_difference(list1, list2): # Initialize the minimum difference to a large number min_diff = float('inf') for a in list1: for b in list2: # Update min_diff only if the difference # between a and b is smaller than min_diff min_diff = mi [instruction] | Design and implement a function that takes two lists of integers as parameters and returns the minimum difference between two elements of the two lists. [input] | list1 = [2, 4, 7, 13] list2 = [3, 8, 9, 14]
[output] | def longest_substring(string): # Initialize the max length and the substring max_length = 0 substring = '' # Create an empty set to store previously seen characters char_set = set() # Iterate over the string for char in string: # If the character hasn't already [instruction] | Find the longest substring with non-repeating characters [input] |
[output] | for item in my_list: print(item) [instruction] | Create a for loop in Python to iterate over all items in a list. [input] | my_list = [1, 2, 3, 4, 5]
[output] | Supervised learning is a type of machine learning that uses labeled data to train algorithms to predict outcomes. It involves using labeled data points as input and output to teach the machine how to predict outcomes. The algorithm is “supervised” because it has a pre-defined set of examples to lear [instruction] | Describe in code what is supervised learning. [input] |
[output] | using System; class Fibonacci { static void Main() { int n1 = 0, n2 = 1, n3, i, number; Console.Write("Enter the number of elements: "); number = int.Parse(Console.ReadLine()); Console.Write(n1 + " " + n2 + " "); for (i = 2; i < number; ++i) [instruction] | Construct a C# program to display Fibonacci series. [input] |
[output] | SELECT * FROM sales ORDER BY id DESC LIMIT 3 [instruction] | Rewrite this SQL query to select the top three records from a table named 'sales'. [input] | SELECT * FROM sales
[output] | def convert_to_binary(num): binary = "{0:b}".format(num) return binary # Convert 15 to binary binary_value = convert_to_binary(15) print(binary_value) # prints "1111" [instruction] | Construct a function convert a given number to binary format. [input] | Input Number: 15
[output] | def min_partition_array(arr): total = 0 for i in arr: total += i sum1, sum2 = 0, total n = len(arr) flag = [[False for i in range(total + 1)] for j in range(n + 1)] flag[0][0] = True for i in range(1, n + 1): for j in range(total + 1): if arr[i [instruction] | Design a program to partition an array into two subarrays such that the difference between the sum of the two subarrays is minimum. [input] | Input Array: [1, 6, 5, 11, 3]
[output] | # Symbols for the different ranks ranks = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"] # Symbols for the different suits suits = ["Clubs", "Diamonds", "Hearts", "Spades"] # Create a deck of cards as a 2D array deck = [] for i in range(len(ranks)): for j in rang [instruction] | Edit the program such that it prints the elements in a deck of cards in a specific format. [input] |
[output] | import re my_string = 'This is (a sample) string with (parentheses)' op = re.sub(r'\([^)]*\)', '', my_string) print(op) [instruction] | Suggest a method to remove the pair of parentheses ( ) and the words inside them from the following python string. [input] | my_string = 'This is (a sample) string with (parentheses)'
[output] | class Car: def __init__(self, color, model): self.color = color self.model = model def start(self): print("Starting car") def stop(self): print("Stopping car") [instruction] | Create a Python class for a car with two methods. [input] |
[output] | .text { font-size: 12px; } [instruction] | Given the following HTML code, write a CSS rule to change the font size to 12px. [input] | <p class=”text”>Test</p>
[output] | SELECT A.id, A.name,B.owner FROM A JOIN B ON A.id = B.id; [instruction] | Create a SQL query that combines two tables ``A`` and ``B``. [input] | Table A id name 1 car 2 bike Table B id owner 1 Sam 2 John
[output] | for i in range(1,100): if i % 7 == 0: print(i, end=" ") [instruction] | Write a loop in Python to find all numbers below 100 that are divisible by 7. [input] |
[output] | A suitable machine learning algorithm for this task is a supervised learning algorithm, such as a Naive Bayes classifier. [instruction] | Suggest a suitable type of machine learning algorithm for the following task. [input] | Identifying the sentiment of a movie review.
[output] | def div(x, y): if y == 0: raise ValueError('Cannot divide by zero') else: return x // y [instruction] | Create a function to divide two numbers and return an integer result. [input] |
[output] | def countUpperCase(string): # Initialize counter variable count = 0 # Loop through characters in string for c in string: # If character is upper case increment counter if c.isupper(): count += 1 return count [instruction] | Create a function that will take a string as an input and returns the number of upper case letters in it. [input] |
[output] | SELECT COUNT(*) as count_user_id FROM users; [instruction] | Write a SQL query to count the number of records with a field of "user_id" in the table called "users". [input] |
[output] | let sum = numbers.reduce((total, num) => total + num); console.log(sum); // 15 [instruction] | Use the reduce() method to sum the values of an array of numbers in JavaScript. [input] | const numbers = [1, 2, 3, 4, 5];