[output] | // Generating two random numbers from 1 to 6 let rand1 = Math.floor(Math.random() * 6) + 1; let rand2 = Math.floor(Math.random() * 6) + 1; // Calculating and displaying the dice sum let diceSum = rand1 + rand2; console.log("Dice sum: " + diceSum); [instruction] | Display the dice sum of two random numbers from 1 to 6. [input] |
[output] | for (let i = 0; i < array.length; i++) { console.log(array[i]); } [instruction] | Output the contents of the array ["Hello", "World", "AI", "Machine Learning"] using a for loop. [input] |
[output] | const filteredArray = arr => arr.filter(num => num <= 10); console.log(filteredArray([2, 10, 11, 19, 3, 4])); // Output: [2, 10, 3, 4] [instruction] | Design a function in Javascript to filter out the values of an array that are greater than 10. [input] | [2, 10, 11, 19, 3, 4]
[output] | public class MaxElement { public static void main(String[] args) { int[] arr1 = {2, 8, 7, 2, 8, 2, 6}; int count = 1; int max_element=arr1[0]; int temp_count; for (int i = 0; i < arr1.length; i++) { temp_count = 1; fo [instruction] | Write a Java program to find the element that appears maximum number of times in an array. [input] | int [] arr1 = {2, 8, 7, 2, 8, 2, 6}
[output] | I like ice cream. [instruction] | You need to edit the wrong sentence appropriately. [input] | I likes ice cream.
[output] | square = lambda x: x * x [instruction] | Rewrite the following code using lambda expression instead. [input] | def square(x): return x * x
[output] | #include<iostream> #include<queue> using namespace std; // A Binary Tree Node struct Node { int data; struct Node *left, *right; }; // Function to print the level order traversal of the tree void levelOrder(struct Node *root) { // Base Case if (root == NULL) return; // Crea [instruction] | Print a binary tree level by level, starting from the root level. [input] |
[output] | for i in range(1, n + 1): print(i, end=" ") [instruction] | Construct a for-loop to print all numbers from 1 to n, separated by a space. [input] |
[output] | def quick_sort(arr): if len(arr) <= 1: return arr pivot = arr[0] left = [] right = [] for i in range (1, len(arr)): if arr[i] < pivot: left.append(arr[i]) else: right.append(arr[i]) left = quick_sort(left) right = quick_sort [instruction] | Suggest a better approach to sort the given array. [input] | [4, 3, 8, 6, 7, 9, 2, 1]
[output] | def intersection(head1, head2): s = set() current1 = head1 current2 = head2 while current1 is not None: s.add(current1.data) current1 = current1.next result = [] while current2 is not None: if current2.data in s: result.append(current2.data [instruction] | Write a function to give the intersection of two unsorted linked lists. [input] |
[output] | s = "name=John, age=45, gender=m" d = dict() for x in s.split(','): d[x.split('=')[0].strip()] = x.split('=')[1].strip() [instruction] | Parse the following string and store each key-value pair into a dictionary. [input] | "name=John, age=45, gender=m"
[output] | He lwrd [instruction] | Write an efficient Python program to remove duplicate characters from the given string. [input] | String: Hello world
[output] | let input = 'example'; if (input.length === 7) { console.log('Input is valid'); } else { console.log('Input is not valid'); } [instruction] | Write a JavaScript program to validate the given input against a set of rules. [input] | Rules: Length should be equal to 7 Input = 'example'
[output] | import React from "react"; const BlogPost = () => { return ( <div> <h1>Why React is the Best Framework</h1> <p> React is one of the most popular JavaScript frameworks today and is used by many companies and developers. It boasts of its component-based architecture and powerful features [instruction] | Create a blog post using React JS. [input] | Blog Title: Why React is the Best Framework
[output] | <html> <head> <title>Registration Form</title> <style> body { font-family: sans-serif; } .container { width: 500px; margin: 0 auto; } .form-steps { padding: 20px 0; } .form-step { padding: 10px; border: 1px solid #ccc; background-color: #eee; } .active { b [instruction] | Create an HTML page of a multi-step registration form. [input] | Step 1: Name and Email Step 2: Address Step 3: Password
[output] | function merge(a, b) { return Object.assign({}, a, b); } let result = merge(a, b); console.log(result); // {name: 'John', age: 21, surname: 'Doe', gender: 'male'} [instruction] | Create a JavaScript function to merge two variables into a single object. [input] | var a = {name: 'John', age: 21}; var b = {surname: 'Doe', gender: 'male'};
[output] | import requests from bs4 import BeautifulSoup url = 'http://www.cnn.com/' response = requests.get(url) html_content = response.text soup = BeautifulSoup(html_content, "lxml") top_headlines = soup.find_all('h3',{'class':'cd__headline'}) for headline in top_headlines[:5]: print(headline.text) [instruction] | Write a Python program to fetch and print the top five headlines from a given news website. [input] | News Website: CNN
[output] | SELECT name FROM customers WHERE orders > 500; [instruction] | Write a SQL command to get a list of customers with order total greater than 500. [input] | TABLE customers { id INT, name VARCHAR(90), orders TOTAL DEC(10,2) }
[output] | isEvenDivisible :: Integer -> Integer -> Bool isEvenDivisible x y = (x `mod` y) == 0 [instruction] | Write a Haskell function to check if two numbers are evenly divisible. [input] |
[output] | const person = { name: 'John Doe', age: 36, profession: 'developer' }; [instruction] | Construct a JavaScript object with three properties: name, age, and profession. [input] |
[output] | <html> <head> <title>Example HTML</title> </head> <body> <h1>Heading</h1> <p>This is a paragraph.</p> <a href="www.example.com">Link to example.com</a> </body> </html> [instruction] | Write an HTML document with a heading, a paragraph and a link to www.example.com. [input] |
[output] | SELECT c.name, o.order_id, o.total FROM customers c JOIN orders o ON c.id = o.customer_id; [instruction] | Write a SQL command to join the 'customers' and 'orders' tables on the 'customer_id' column. [input] | TABLE customers { id INT, name VARCHAR(90) } TABLE orders { order_id INT customer_id INT total DEC(10,2) }
[output] | <html> <head> <title>Example HTML</title> </head> <body> <h1>Heading</h1> <p>This is a paragraph.</p> <form> Name: <input type="text" name="name" /> Age: <input type="number" name="age" /> <input type="submit" /> [instruction] | Write a HTML web page with a heading, paragraph, and a form with two input fields, one for name and one for age. [input] |
[output] | SELECT c.name, SUM(o.total) FROM customers c JOIN orders o ON c.id = o.customer_id GROUP BY c.name; [instruction] | Construct an SQL query to get the total sales of each customer. [input] | TABLE customers { id INT, name VARCHAR(90) } TABLE orders { order_id INT customer_id INT total DEC(10,2) }
[output] | The function returns a string, "true" which is invalid. The function should return a boolean value instead (True or False). [instruction] | Identify the incorrect statement about the following code fragment. [input] | def is_over21(age): if age > 21: return “true” else: return
[output] | x+y >= 12 #expression to evaluate to true. [instruction] | Construct an expression that combines the two values x and y so that the following statement evaluates to true [input] | x = 4 y = 8
[output] | calculated value = b/float(a) #Suggested correction. [instruction] | Suggest correction to the following calculated value. [input] | a = 3 b = 5 calculated value = b/a
[output] | The difference between int and float data type is that a float data type stores double numerically accurate values. This is because a float can represent a wider range of numbers when compared to an int, and therefore it requires double the memory. [instruction] | Fill in the blank and explain why it works. [input] | The difference between int and float data type is that a float data type stores ____ numerically accurate values.
[output] | \d{6} #This regular expression will validate a 6-digit numeric zipcode. [instruction] | Construct a regular expression for validating a 6-digit numeric zip code [input] |
[output] | def remove_duplicates(input_list): return list(set(input_list)) #This is more efficient than iterating over the list to remove duplicate items. [instruction] | How could the following code be optimized? [input] | def remove_duplicates(input_list): temp_list = [] for item in input_list: if item not in temp_list: temp_list.append(item) return temp_list