[output] | lens = [] for name in names: lens.append(len(name)) [instruction] | You are given a list of names. Create a list whose elements are the length of each name in the original list. [input] | names = ["Max", "John", "Cindy", "Sarah"]
[output] | sentence = input("Please enter a sentence: ") words = sentence.split() words.reverse() sentence = " ".join(words) print(sentence) [instruction] | Read a sentence from the user, and then reverse its words in place. [input] |
[output] | def check_list(lst, item): return item in lst def check_list_version2(lst, item): for x in lst: if x == item: return True return False [instruction] | Create two functions to check if a given list contains a specific element. [input] | list = [4, 1, 6, 9, 8] item = 8
[output] | lst.sort() [instruction] | Given a list of numbers, sort them from smallest to largest. [input] | lst = [3, 5, 2, 6, 8, 1]
[output] | for (name1, name2) in lst: first_name = name1 last_name = name2 [instruction] | Unpack the elements in the given list of tuples and assign them to individual variables. [input] | lst = [("Max", "Smith"), ("John", "Doe"), ("Cindy", "Wilson")]
[output] | res = str1 + str2 [instruction] | Given two strings, concatenate them together and assign the result to a variable. [input] | str1 = "Hello" str2 = "World"
[output] | total = 0 for s in lst: total += int(s) [instruction] | Convert the following list of strings to integers and calculate their total. [input] | lst = ["4", "5", "2", "6", "8", "1"]
[output] | function getRandomString(){ let chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; let str = ''; for (let i=0; i<8; i++) str += chars.charAt(Math.floor(Math.random() * chars.length)); return str; } [instruction] | Write a JavaScript function to generate a random string of 8 characters using lowercase alphabets and digits. [input] |
[output] | <html> <head> <title>My Website</title> </head> <body> <footer> <p>Copyright © 20 [instruction] | Edit this HTML structure to add a footer at the bottom. [input] | <html> <head> <title>My Website</title> </head> <body> </body> </html>
[output] | <html> <head> <title>Generating HTML Page</title> <meta name="author" content="GPT" /> </head> <body> <p>This is an example of how you can generate an HTML page.</p> </body> </html> [instruction] | Generate an HTML page with the following data fields: title, author, and content. [input] | title: Generating HTML page author: GPT content: This is an example of how you can generate an HTML page.
[output] | d = {'a':1, 'b':2, 'c':3} for key in d: print(key) [instruction] | Modify the following code to print the keys of a dictionary. [input] | d = {'a':1, 'b':2, 'c':3}
[output] | SELECT column_name FROM table_name; [instruction] | Write a SQL query which will select column names from a certain table. [input] |
[output] | One algorithm to find the least common multiple of two numbers is as follows: Step 1: Find the greatest common divisor (GCD) of the two numbers. Step 2: Divide the product of the two numbers by the GCD to find the least common multiple (LCM). The GCD of two numbers can be found using the Euclidean [instruction] | Create an algorithm for finding the least common multiple of two numbers. [input] |
[output] | for (int i = 0; i < array.length; i++) { System.out.println(array[i]); } [instruction] | Construct a for loop in Java for iterating through an array. [input] |
[output] | x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] [instruction] | Replace the content of the variable ``x`` with a list of numbers. [input] | x = <noinput>
[output] | import math for i in range(0,11): print(math.sqrt(i)) [instruction] | Create a for loop to output the square roots of the numbers between 0 and 10 using the math library. [input] |
[output] | def print_twice(string): print(string) print(string) [instruction] | Construct a helper function that prints the provided string twice. [input] |
[output] | if (number % 2 == 0): print("This is an even number") else: print("This is an odd number") [instruction] | Form an if-else condition that prints “This is an even number” if a number is even and “This is an odd number” if the number is odd [input] | number = 5
[output] | for i in range(len(string)-1, -1, -1): print(string[i], end="") [instruction] | Construct a loop that prints the characters of the given string in reverse order. [input] | string = 'Hello World'
[output] | list_dict = { 'apple': 5, 'banana': 6, 'cherry': 6 } [instruction] | Make a dictionary that contains the number of characters in each word from this list. [input] | list = ['apple', 'banana', 'cherry']
[output] | 1. Using for loop: for key, value in dict.items(): # Do something with key and value 2. Using while loop: keys = list(dict.keys()) i = 0 while i < len(keys): key = keys[i] value = dict[key] # Do something with key and value i += 1 [instruction] | Suggest two ways to loop through a python dictionary [input] |
[output] | SELECT CITY, COUNT(*) as Occurrences FROM person GROUP BY City ORDER BY Count(*) DESC LIMIT 5; [instruction] | Write a SQL query to extract the top 5 occurrences of the city names from the following table. [input] | Table: person ╔════╦═══════╦═════════╗ ║ id ║ name ║ city ║ ╠════╬═══════╬═════════╣ ║ 1 ║ Ann ║ Paris ║ ║ 2 ║ Jack ║ Tokyo ║ ║ 3 ║ Tom ║ Tokyo ║ ║ 4 ║ Daisy ║ Paris ║ ║ 5 ║ John ║ London ║ ║ 6 ║ Paul ║ London ║ ╚════╩═══════╩═════════╝
[output] | print("Hello","|".join([str(x) for x in [1,2,3]])) [instruction] | Edit this line of code to make it work according to our requirements. [input] | print("Hello",[1,2,3],sep='|')
[output] | MOV AL, 8 MOV CX, Size CLD LOOP: LODSW ADD AL, 8 STOSW LOOP LOOP [instruction] | Write an assembly code to perform the task of incrementing a memory block by 8. [input] |
[output] | <body> <p>Some other text here</p> <h1>Important Text</h1> </body> [instruction] | Insert this HTML element at the appropriate place. [input] | <h1>Important Text</h1>
[output] | public void fill(int[] array, int n) { for (int i = 0; i < n; i++) { array[i] = i + 1; } } [instruction] | Write some Java code to fill in an array of size n with all consecutive numbers from 1 to n. [input] |
[output] | The given code does not have any mistakes. All the syntax is correct and the code will perform its intended operation. The indentation of the code is also correct. However, it could be improved by adding descriptive variable and function names, adding comments to explain the code's purpose and by ma [instruction] | Identify the mistakes in the below code. [input] | def add_two_numbers(x, y): a = x + y return a
[output] | SELECT DISTINCT * FROM table_name; [instruction] | Rewrite the following Java code into SQL to select all the distinct elements from a table. [input] | String sql = "SELECT DISTINCT * FROM table_name";
[output] | def fibonacci_sequence(n): nums = [] a, b = 0,1 for i in range(n): nums.append(a) a, b = b, a + b return nums print(fibonacci_sequence(7)) [instruction] | Generate a Python Fibonacci sequence of length n [input] | n = 7
[output] | version: '3' services: web_app: image: my_web_app:v1 deploy: replicas: 1 restart_policy: condition: on-failure [instruction] | Spin up a container for an application with Docker-Compose [input] | Web App Image: my_web_app:v1