[output] | def swapNumbers(a, b): temp = a a = b b = temp print("After swapping: a =", a, " b =", b) # Driver program a = 10 b = 20 swapNumbers(a, b) [instruction] | Design an algorithm to swap two numbers in Python. [input] | Swap 10 and 20
[output] | #include <iostream> using namespace std; float kms_to_miles(float kms) { return kms * 0.621; } int main() { float kms = 10; cout << kms << " kilometers is equal to " << kms_to_miles(kms) << " miles"; return 0; } [instruction] | Create a program to convert kilometers to miles in C++. [input] | Convert 10 kilometers to miles
[output] | A megabyte is equal to 1,048,576 bytes. [instruction] | How many bytes are there in a megabyte? [input] |
[output] | int[, ,] array3D = new int[x, y, z]; [instruction] | Create a 3-dimensional array of ints in C#. [input] |
[output] | def sum_of_squares(n): sum_squares = 0 for i in range(1, n+1): sum_squares += i**2 return sum_squares [instruction] | Design a function to calculate the sum of the squares of the numbers between 1 and n. [input] |
[output] | import git #clone the repository repo = git.Repo.clone_from("[https://github.com/user/myproject.git](https://github.com/user/myproject.git)", "myproject") [instruction] | Create a script to clone a GitHub repository. [input] | The repository name is "myproject".
[output] | void printList(List<String> list) { for (String item : list) { System.out.println(item); } } [instruction] | Rewrite the code below using Java [input] | def print_list(list): for item in list: print(item)
[output] | function isPalindrome(str) { let start = 0; let end = str.length - 1; while (start < end) { if (str[start] !== str[end]) { return false; } start++; end--; } return true; } [instruction] | generate a JavaScript function to check whether a string is a palindrome. [input] |
[output] | SELECT FirstName FROM Employee WHERE CompanyID = <user-provided-id>; [instruction] | Design a SQL query to find the first name of all employees of a company. [input] | Table "Employee" with columns: FirstName, LastName, Email, CompanyID
[output] | if (Array.isArray(variable)) { console.log('It is an array'); } else { console.log('It is not an array'); } [instruction] | Write a JavaScript code snippet to test if a given variable is an array or not. [input] |
[output] | del sample_dic['name'] [instruction] | Suggest a code snippet in Python to delete the dictionary entry with a key called "name". [input] | sample_dic = {'id': 123, 'name': 'John Doe'}
[output] | SELECT * FROM movies WHERE rating > 3; [instruction] | Create a SQL statement to list all the entries with a rating greater than 3 from the table "movies". [input] |
[output] | SELECT title, description FROM movies WHERE rating > 3; [instruction] | Create an SQL statement to select the title and description of all movies with a rating greater than 3. [input] |
[output] | function capitalizeWords(str) { let words = str.split(' '); let capitalizedWords = words.map(word => word[0].toUpperCase() + word.slice(1)); return capitalizedWords.join(' '); } [instruction] | Write a function in JavaScript to capitalize all the words in a given phrase. [input] |
[output] | int sum = 0; for (int i=0; i<size; i++) sum += arr[i]; [instruction] | Suggest a code snippet in C++ to calculate the sum of all the elements of a given array. [input] |
[output] | A recursive function is a function that calls itself until a certain condition is met. It takes in an argument and performs some operation, then calls itself with a modified version of the argument until the condition is satisfied. The result of each call is combined in some fashion to form the fina [instruction] | Describe the working of a recursive function. [input] |
[output] | { "studentDetails": { "name": "John Doe", "age": 25, "address": { "street": "XYZ Street", "city": "New York", "state": "NY" } } } [instruction] | Prepare a JSON object to store student details such as name, age, and address. [input] |
[output] | Linear search is a searching algorithm for finding an element within an array or a list. It sequentially checks each item of the list until a match is found or the end of the array is reached. If the key is found, the index position of the element is returned. If the element is not found, then the i [instruction] | Describe linear search algorithm. [input] |
[output] | SELECT books.book_title, authors.author_name FROM books INNER JOIN authors ON books.author_id = authors.author_id; [instruction] | Write an SQL query to join two tables named 'books' and 'authors' on author_id. [input] |
[output] | int[] array = new int[10]; for (int i = 0; i < array.length; i++) { array[i] = 0; } [instruction] | Construct an array of 10 elements in Java and initialize each element to 0. [input] |
[output] | <html> <head> <title>Hello World!</title> </head> <body> <h1>Hello World!</h1> </body> </html> [instruction] | Create an HTML page that displays "Hello World!" when opened in a web browser. [input] |
[output] | In C++, a unary operator is an operator that takes only a single operand to perform an action. Examples of unary operators include the negation operator (!), increment operator (++), decrement operator (--), and address-of operator (&). [instruction] | What is the unary operator in C++? [input] |
[output] | class HelloGoodbye { public static void sayHello() { System.out.println("Hello!"); } public static void sayGoodbye() { System.out.println("Goodbye!"); } } [instruction] | Construct a class in Java that has two methods called 'sayHello' and 'sayGoodbye'. [input] |
[output] | The advantages of using a graphical user interface (GUI) include improved usability and accessibility, better visual communication of information, easier drag-and-drop capabilities, improved data visualization, and the ability to add graphics, sound and video to enhance user experience. GUI's also f [instruction] | What are the advantages of using a graphical user interface? [input] |
[output] | import matplotlib.pyplot as plt data = [3, 5, 8, 1, 9, 12] plt.hist(data, color='blue', ec='black') plt.title("Histogram") plt.xlabel("Values") plt.ylabel("Frequency") plt.show() [instruction] | Write a script in Python for generating a histogram for a given set of data. [input] | [3, 5, 8, 1, 9, 12]
[output] | function generateArray() { let arr = []; for (let i = 1; i <= 10; i++) { arr.push(i); } return arr; } console.log(generateArray()); Output: [1,2,3,4,5,6,7,8,9,10] [instruction] | Create a function in Javascript to return an array containing the numbers from 1 to 10. [input] |
[output] | function reverse_array($a) { $n = count($a); $temp=null; for ($i=0; $i<$n/2; $i++) { $temp = $a[$i]; $a[$i] = $a[$n-$i-1]; $a[$n-$i-1] = $temp; } return $a; } print_r(reverse_array([3, 5, 8, 1, 9, 12])); Output: Array ( [0] => 12 [1] => 9 [2] => 1 [3] => 8 [4] => 5 [5] => 3 ) [instruction] | Create a function in PHP that reverses the order of an array. [input] | [3, 5, 8, 1, 9, 12]
[output] | def calculate_discount(self): discount = self.price - (self.cash_coupon + (self.price * self.percentage_coupon / 100)) return discount [instruction] | Given the class definition below, write a method to calculate the discount. [input] | class DiscountCalculator: def __init__(self, price, cash_coupon, percentage_coupon): self.price = price self.cash_coupon = cash_coupon self.percentage_coupon = percentage_coupon
[output] | Python decorator is a function which takes another function as argument and extends the behavior of that function without modifying its code. It allows developers to modify the behavior of a function, class or method at runtime without changing the code itself. Decorators are heavily used in framewo [instruction] | Explain the concept behind the Python decorator. [input] |
[output] | def wrap_in_box(text, length, padding): border = "" for i in range(length): border += "-" space = "" for i in range(padding): space += " " text = space + text + space if len(text) > length: text = text[:length-1] text = text.center(length) p [instruction] | Write a code to wrap a text in a box, with the given length and padding parameters. [input] | text = "Hello World!", length = 20, padding = 5