[output] | import pandas as pd data = { 'name': ["James"], 'age': [60], 'street': ["123 Fake Street"], 'city': ["Springfield"], 'state': ["MA"], } df = pd.DataFrame(data) print(df) # Output: name age street city state 0 James 60 123 Fake Street Springfield MA [instruction] | Using the Pandas library, parse the given json object. [input] | { "name": "James", "age": "60", "address":{ "street": "123 Fake Street", "city": "Springfield", "state": "MA" } }
[output] | import numpy as np array = np.random.randint(0, 10, size=(3, 3)) print(array) # Output: [[5 4 9] [6 8 5] [4 7 6]] [instruction] | Generate a numpy array of shape (3,3) with random values between 0 and 10. [input] |
[output] | def sum_factors(n): total = 0 for i in range(1, n + 1): if n % i == 0: total += i return total sum_factors(12) # Output: 28 [instruction] | Find the sum of factors of a given number. [input] |
[output] | def is_subset(s1, s2): for e in s1: if e not in s2: return False return True is_subset({1,2,3}, {1,2,3,4,5,6}) # Output: True [instruction] | Create a function that returns true if a given set is a subset of another set. [input] | set1 = {1,2,3} set2 = {1,2,3,4,5,6}
[output] | def matrix_dimensions(matrix): num_rows = len(matrix) num_columns = len(matrix[0]) return num_rows, num_columns matrix = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] num_rows, num_columns = matrix_dimensions(matrix) print(num_rows) # Output will be 3 print(num_co [instruction] | Design a function that takes in a matrix and finds its number of rows and columns. [input] | matrix = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
[output] | class Vehicle: def __init__(self, make, model, year): self.make = make self.model = model self.year = year # Other methods... [instruction] | Create a class definition in Python for a vehicle with attributes like make, model, year. [input] |
[output] | def is_armstrong(num): digits = [int(d) for d in str(num)] num_digits = len(digits) armstrong_sum = 0 for digit in digits: armstrong_sum += digit ** num_digits return num == armstrong_sum #Test code num = 153 print(is_armstrong(num)) # Output will be True [instruction] | Explain a Python program to check whether a number is Armstrong or not. [input] |
[output] | def get_high_scorers(students): # Get the names of students with marks greater than 80 high_scorers = [] for student in students: if student[1] > 80: high_scorers.append(student[0]) return high_scorers students = [("John", 75), ("Mary", 90), ("Simon", 80), ("Rose [instruction] | Design a program to select the names of the students who have secured more than 80% marks in a given exam. [input] | students = [("John", 75), ("Mary", 90), ("Simon", 80), ("Rose", 80)]
[output] | class Point { private: int x, y; public: Point(int x, int y) : x{x}, y{y} {}; Point operator + (const Point& other) { return Point(this->x + other.x, this->y + other.y); } }; [instruction] | Design a class in C++ to represent a 2D point and define the addition operation for two points. [input] | class Point { private: int x, y; public: Point(int x, int y) : x{x}, y{y} {};
[output] | import pandas as pd df = pd.DataFrame([ [8, 'B', 'G'], [28, 'B', np.nan], [22, np.nan, 'G'], [2, 'A', np.nan] ]) df.fillna(value='NA', inplace=True) [instruction] | Write Python code to fill missing values in a Pandas dataframe with a given value. [input] | import pandas as pd df = pd.DataFrame([ [8, 'B', 'G'], [28, 'B', np.nan], [22, np.nan, 'G'], [2, 'A', np.nan] ])
[output] | This is a heading [instruction] | Read this HTML code and extract the content between the <h1> and </h1> tags. [input] | <h1>This is a heading</h1>
[output] | SELECT * FROM table_name ORDER BY id ASC [instruction] | Write a MySQL statement to sort the table results by the column "id" in ascending order. [input] | SELECT * FROM table_name
[output] | function isEmptyObject(obj) { return Object.keys(obj).length === 0; } [instruction] | Implement a function in JavaScript that returns true if an object is empty, false otherwise. [input] |
[output] | <form action=""> <label>Name:</label> <input type="text" name="name" placeholder="Your name" required><br><br> <label>Email:</label> <input type="email" name="email" placeholder="Your email address" required><br><br> <input type="submit" value="Submit"> </form> [instruction] | Create a HTML form to take user input from a web page. [input] |
[output] | The syntax error is that 'console.WriteLine("Hello");' should be within a pair of curly braces. i.e. The correct syntax should be "if (x > 4) { Console.WriteLine("Hello") };" [instruction] | Find the syntax error in the given C# code. [input] | int x = 5; if (x > 4) console.WriteLine("Hello");
[output] | Polymorphism is a feature in object-oriented programming that allows objects to behave differently depending on the context. It is used to reduce the amount of code needed for different operations and to increase the code's maintainability. Polymorphism allows objects to be defined from a common cla [instruction] | Define the term "polymorphism" in programming. [input] |
[output] | <form action="action.php" method="post"> <label for="email">Email:</label><br> <input type="text" name="email" placeholder="Enter your email"><br><br> <input type="submit" value="Submit"> </form> [instruction] | Create an HTML form that takes one input field - an email address. [input] |
[output] | SELECT * FROM customers WHERE name LIKE 'A%'; [instruction] | Create a select query to fetch all the customers with a name starting with 'A'. [input] |
[output] | ifconfig | grep "inet " | awk '{ print $2 }' [instruction] | Write a shell command to print the system IP address. [input] |
[output] | function getDomainFromEmail(email_address) { return email_address.split('@')[1]; } getDomainFromEmail('example@domain.com'); // 'domain.com' [instruction] | How to extract the domain name from an email address using JavaScript? [input] |
[output] | function greet(name) { return 'Hello ' + name + '!'; } [instruction] | Create a function 'greet' that takes a string parameter 'name' and returns the string 'Hello name!' [input] |
[output] | var arr = [10, 11, 12, 13, 14]; [instruction] | Create an array of 5 increasing numbers starting from 10. [input] |
[output] | SELECT * FROM employees ORDER BY age DESC LIMIT 5; [instruction] | Write a SQL query to return the 5 oldest employees from a table named 'employees'. [input] |
[output] | public static String addString(String str1, String str2) { return str1 + str2; } [instruction] | Write a method 'addString' in Java that takes two strings as parameters and returns a single string that concatenates the two strings. [input] |
[output] | def concatenate(str1, str2, str3, str4): return str1 + str2 + str3 + str4 [instruction] | Write a function in Python that takes four strings as parameters and returns a single string with all strings concatenated together. [input] |
[output] | if (number > 0) { console.log('positive'); } else if (number < 0) { console.log('negative'); } [instruction] | Write an if-else statement in JavaScript that prints 'positive' if a number is greater than 0 and 'negative' if a number is less than 0. [input] |
[output] | def subStr(str, start, end): return str.substring(start, end) [instruction] | Create a function 'subStr' that takes a string and a start and end index and returns a substring between the start and end index. [input] |
[output] | SELECT * FROM users WHERE birthdate > 1985; [instruction] | Write a SQL query to select the users from table 'users' who are born after 1985. [input] |
[output] | public static String LowerCase(String str) { return str.toLowerCase(); } [instruction] | Create a function in Java that takes a string as a parameter and returns the string in lowercase letters. [input] |
[output] | In Java, to create a linked list, you need to declare a node class with instance variables for data and reference to the next node. Then create a LinkedList class with a head node and other methods for insertion, deletion and searching in the linked list. To add an element to the linked list, create [instruction] | Provide instructions to create a linked list in Java. [input] |