[output] | # Take a number from user num = int(input("Enter a number: ")) # Check whether the number is odd or even if num % 2 == 0: print("Number is even.") else: print("Number is odd.") [instruction] | Create a program that will take a number from the user and print out whether the number is odd or even. [input] |
[output] | SELECT * FROM product_catalog WHERE price > 100; [instruction] | Write a SQL query to find the records with a price greater than 100 from a table called "product_catalog". [input] |
[output] | SELECT * FROM table_name WHERE name LIKE 'A%'; [instruction] | Write an SQL query to find the records with a name starting with "A". [input] |
[output] | <html> <head> <title>Centered Paragraph</title> </head> <body> <div style="text-align:center;"> <p>This is a centered paragraph.</p> </div> </body> </html> [instruction] | Write an HTML code to display a webpage with a centered paragraph. [input] |
[output] | def triangle_area(a, b, c): '''This function computes the area of a triangle given its side lengths.''' # Calculate semi-perimeter s = (a + b + c) / 2 # Calculate the area area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 return area print("The area of the triangle is:", trian [instruction] | Write a Python script to find the area of a triangle with sides 18, 24, and 30. [input] |
[output] | .container { color: red; } [instruction] | Generate CSS code to set the font color of a div with class "container" to red. [input] |
[output] | #include <iostream> using namespace std; int main() { for (int i = 7; i <= 50; i+= 7) { cout << i << " "; } cout << endl; return 0; } [instruction] | Develop a C++ program to list all the numbers divisible by 7 from 1 to 50. [input] |
[output] | The efficient way to sort the array using Java is to use the Quicksort algorithm which is an in-place, recursive sorting algorithm with an average time complexity of O(n log n). The Quicksort algorithm works by selecting an element as a pivot, partitioning the array around the pivot, and recursively [instruction] | Suggest an efficient way to sort the following array using Java. [input] | [3, 4, 6, 2, 9, 8, 1]
[output] | class MyClass: def __init__(self): pass def function1(self): pass def function2(self): pass def function3(self): pass def function4(self): pass [instruction] | Create a class in python with 4 functions. [input] |
[output] | list3 = [3,4,5] [instruction] | You are given two lists. Output a third list which contains only the elements common to both lists. [input] | list1 = [1, 2, 3, 4, 5] list2 = [3, 4, 5, 6, 7]
[output] | [0, 1, 1, 2, 3, 5] [instruction] | Take a number input and output the Fibonacci sequence up to that number. [input] | n = 5
[output] | import numpy as np random_array = np.random.random_integers(1,10,10) print(random_array) [instruction] | Using the 'arrays' library in Python, generate a random array of 10 numbers. [input] |
[output] | #!/bin/bash # # Check if two files are the same # if [ "$#" -ne 2 ]; then echo "Error: please provide two filenames as arguments to this script" exit 1 fi # get the absolute paths to the two files: file1=$(realpath $1) file2=$(realpath $2) if [ "$file1" == "$file2" ]; then echo "The two fil [instruction] | Create a shell script which takes two filenames as arguments and checks if they are the same. [input] |
[output] | def addToList(list, int): new_list = [] for l in list: new_list.append(l + int) return new_list result = addToList(list, integer) print(result) # [6, 7, 9] [instruction] | Create a Python function that takes two arguments: a list and an integer. The function should add the given integer to each element of the list and return the new list. [input] | list = [2, 3, 5] integer = 4
[output] | def combineTwoLists(list1, list2): new_list = list1 + list2 return new_list result = combineTwoLists(list1, list2) print(result) # [1, 2, 3, 4, 5, 6] [instruction] | Create a function 'combineTwoLists' with two parameters which combines two given lists into a new list. [input] | list1 = [1, 2, 3] list2 = [4, 5, 6]
[output] | #!/bin/bash input=$1 if [ $input -eq $input 2> /dev/null ]; then echo "$input is a number" else echo "$input is a string" fi [instruction] | Write a Bash script which detects if a given argument is a number or a string. [input] |
[output] | function sum(a, b) { return a + b; } let result = sum(5, 6); console.log(result); // 11 [instruction] | Create a function 'sum' in JavaScript with two parameters which adds the two numbers passed in. [input] |
[output] | def findPattern(str1, str2): ind = 0 for ch in str2: if ch not in str1[ind:]: return 0 ind = str1.index(ch, ind) + 1 return 1 # Driver code if findPattern("timetopractice", "top"): print("Subsequence Found") else: print("Subsequence No [instruction] | Create a Python function 'findPattern' with two parameters which takes two strings and returns 1 if the second string is a subsequence of the first string, otherwise 0. [input] |
[output] | SELECT * FROM books WHERE title LIKE '%Science%'; [instruction] | Write a SQL query to find the books in the library whose title included the word "Science". [input] |
[output] | The data type of a variable that can only contain boolean values in Python is a bool. [instruction] | What is the data type of a variable that can only contain boolean values in Python? [input] |
[output] | The len() method returns the length of a string, while the index() method returns the index of a substring or character in the string. The len() method returns the number of characters or elements in the string, while the index() method returns the starting index of the substring in the string. [instruction] | What is the difference between len() and index() methods in Python? [input] |
[output] | def print_pairs_with_sum(numbers, targetSum): for i in range(len(numbers)): for j in range(i + 1, len(numbers)): if (numbers[i] + numbers[j] == targetSum): print ("(", numbers[i], ",", numbers[j], ")") [instruction] | Write a function that takes an array of numbers and prints out all the pairs of numbers whose sum is equal to a given number. [input] | targetSum = 8 numbers = [1,9,4,3,8]
[output] | SELECT * FROM Employees WHERE salary > (SELECT AVG(salary) FROM Employees); [instruction] | Construct the SQL query to select the rows from the "Employees" table whose salary is greater than the average salary. [input] |
[output] | <html> <head> <title>New Page</title> </head> <body> <div></div> </body> </html> [instruction] | Create a new HTML page and add a <div> element inside the <body>. [input] |
[output] | 5 [instruction] | Retrieve the 5th element from a list named 'numbers'. [input] | numbers = [1, 2, 3, 4, 5, 6, 7, 8]
[output] | This text is about Java programming. [instruction] | Replace all occurence of the string 'Python' in a text with 'Java'. [input] | This text is about Python programming.
[output] | if (isset($name)) { echo "My name is " . $name; } [instruction] | Edit the following PHP code to add an if-statement. [input] | $name = 'John'; echo "My name is " . $name;
[output] | [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] [instruction] | Construct a matrix of shape 7 x 5. [input] |
[output] | def bubbleSort(arr): n = len(arr) # Traverse through all array elements for i in range(n): # Last i elements are already in place for j in range(0, n-i-1): # traverse the array from 0 to n-i-1 # Swap if the element found is greater [instruction] | Implement a function to implement Bubble Sort. [input] |
[output] | if x < 20: print("x is less than 20") [instruction] | Suggest improvements to the code fragment given below. [input] | x = 25 if x < 20 print("x is less than 20")