[output] | int j = 0; for (int i = 0; i < n; i++) { j += i; } [instruction] | Rewrite the following code segment in C#. for (i = 0; i < n; i++) { j = j + i; } [input] |
[output] | Name: John Doe Age: 45 Name: Jane Doe Age: 32 [instruction] | Parse the following XML document and print its content. [input] | <people> <person> <name>John Doe</name> <age>45</age> </person> <person> <name>Jane Doe</name> <age>32</age> </person> </people>
[output] | numberArray = [] for x in range(10, 0, -1): numberArray.append(x) print(numberArray) # [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] [instruction] | Create an array of descending numbers starting from 10 to 1 using a for loop. [input] |
[output] | def even_odd(number): if number % 2 == 0: print("Even") else: print("Odd") [instruction] | How would you implement a function to determine if a number is even or odd in Python? [input] |
[output] | from flask import Flask app = Flask(__name__) @app.route("/hello", methods=["GET"]) def hello(): return "Hello!" [instruction] | Create a Flask route for handling GET requests with the path "/hello". [input] |
[output] | <a href="www.example.com" target="_blank">Example Link</a> [instruction] | Modify the following HTML to create a link that opens in a new window. [input] | <a href="www.example.com">Example Link</a>
[output] | function traverse2DArray(arr) { for(let i=0; i<arr.length; i++) { for(let j=0; j<arr[i].length; j++) { console.log(arr[i][j]); } } } [instruction] | Write a JavaScript code to traverse through a given 2D array. [input] | [ [1, 2], [3, 4], [5, 6] ]
[output] | print(list[:5]) [instruction] | Create a print statement in Python to print the first 5 elements in a list. [input] | [2, 3, 4, 5, 6, 7, 8]
[output] | function foo(param) { // do something with param } foo(param); // pass the parameter here [instruction] | How do you pass a parameter to a function in JavaScript? [input] |
[output] | $.ajax({ url: "test.html", context: document.body }).done(function() { $( this ).addClass( "done" ); }); [instruction] | How can you make an AJAX request using jQuery? [input] |
[output] | for i in range(5): print("Python is the best language!") [instruction] | Modify the code so that it prints "Python is the best language" five times. [input] | for i in range(10): print("Python is great!")
[output] | SELECT * FROM Employees WHERE salary > 30000; [instruction] | Write an SQL query that retrieves all rows from the "Employees" table where the salary is above 30000. [input] |
[output] | count = 0 while count <= 10: print(count) count = count + 1 [instruction] | Modify the program so that the "count" variable counts from 0 to 10 11. [input] | count = 0 while count < 10: print(count)
[output] | square = lambda x: x * x [instruction] | Rewrite the code as a single line with a one-line lambda function. [input] | def square(x): return x * x
[output] | list_a = [1, 2, 3, 4, 5] list_b = [3, 4, 5, 6, 7] not_common_elements = [i for i in list_a if not(i in list_b)] + [i for i in list_b if not(i in list_a)] print(not_common_elements) [instruction] | Write a Python program to compare two lists and print the elements which are not common between the two. [input] | list_a = [1, 2, 3, 4, 5] list_b = [3, 4, 5, 6, 7]
[output] | $("#hidden-element").hide(); [instruction] | Write a jQuery script to hide the element with ID "hidden-element". [input] |
[output] | db.inventory.find( { quantity: { $gt: 10 } } ) [instruction] | Write a MongoDB query that retrieves the documents from the inventory collection where the quantity field is greater than 10. [input] |
[output] | arr = [i for i in range(5)] arr = (i for i in range(5)) [instruction] | Rewrite the loop as a generator expression. [input] | arr = [] for i in range(5): arr.append(i)
[output] | function getCubes(){ var arr = []; for(var i = 1; i <= 10; i++){ arr.push(i*i*i); } return arr; } [instruction] | Write a JavaScript function that generates an array of numbers from 1 to 10 with their cubes. [input] |
[output] | for i in range(10): print(my_list[i]) [instruction] | Construct a loop that prints out the first 10 elements in a given list. [input] | my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
[output] | def is_prime(number): if number < 2: return False for i in range(2, number // 2 + 1): if number % i == 0: return False return True if is_prime(number): print("The number is a prime number") else: print("The number is not a prime number") [instruction] | Create a function that returns true if the given number is a prime number. [input] | number = 9
[output] | # Node class class Node: # Function to initialise the node object def __init__(self, data): self.data = data # Assign data self.next = None # Initialize next as null # Linked List class class LinkedList: # Function to initialize head def __init__(self [instruction] | Write a code that will delete a node in a Linked List at a given position. [input] | # Node class class Node: # Function to initialise the node object def __init__(self, data): self.data = data # Assign data self.next = None # Initialize next as null # Linked List class class LinkedList: # Function to initialize head def __init__(self
[output] | def is_palindrome(string): left, right = 0, len(string)-1 while right >= left: if string[left] != string[right]: return False left += 1 right -= 1 return True if is_palindrome(string): print("The string is a palindrome") else: print(" [instruction] | Write a code that will check if a given string is a palindrome or not without using extra space. [input] | string = "level"
[output] | import random rows = 5 columns = 6 matrix = [[random.randint(1,50) for c in range(columns)]for r in range(rows)] for row in matrix: print(row) [instruction] | Generate a Matrix with random integers between 1-50 and output the Matrix. [input] | rows = 5 columns = 6
[output] | def find_max(my_list): max_num = my_list[0] for num in my_list: if num > max_num: max_num = num return max_num print(find_max(my_list)) [instruction] | Construct a Python program to print out the biggest number from a given list. [input] | my_list = [6, 5, 9, 1, 8, 2]
[output] | <html> <body> <nav> <ul> <li><a href="index.html">Home</a></li> </ul> </nav> </body> </html> [instruction] | Create an HTML NavBar so that clicking on Home takes the user to a Home page [input] | <html> <body> </body> </html>
[output] | def get_person_info(name, age): """Returns a list of tuples containing name and age.""" return [(name, int(age))] [instruction] | Update the given function to return a list of tuples where each tuple contains the name and age of each person. [input] | def get_person_info(name, age): """Returns a tuple containing name and age.""" return "Person " + name + " is " + age + " years old."
[output] | words = ["Alphabet", "Marble", "Buttons"] lowercase_letters = [word.lower() for word in words] print(lowercase_letters) # Output: ['alphabet', 'marble', 'buttons'] [instruction] | Using the given list of strings, create a new list that contains only the lowercase letters. [input] | words = ["Alphabet", "Marble", "Buttons"]
[output] | function convertTo24Hour(timeString) { let [hours, minutes, period] = timeString.split(' '); let [hoursString, minutesString] = hours.split(':'); let hoursInteger = parseInt(hoursString); if (period === 'AM' && hoursInteger === 12) { hoursInteger = 0; } else if (peri [instruction] | Write a JavaScript function to convert the given 12-hour time format to 24-hour format. [input] | time = "12:05 PM"
[output] | def divisor_function(a, b): """Returns the greatest common divisor of two numbers.""" if b == 0: return a else: return divisor_function(b, a % b) [instruction] | Update the given function to return the greatest common divisor of two numbers. [input] | def divisor_function(a, b): """Returns the greatest common divisor of two numbers.""" return a % b