← 목록

Synth · CodeAlpaca일부

총 20,022개 · 페이지 616/668
🔀 랜덤
불러오는 중…

[output] | // evaluate the expression let expression = '7 + 4 * 3 - 6 / 2'; // evaluate the expression let result = eval(expression); // print the result console.log(result); // Output: 19 [instruction] | Evaluate the expression "7 + 4 * 3 - 6 / 2" with JavaScript. [input] |

[output] | // calculate s - the semi-perimeter float s = (4 + 5 + 3) / 2; // calculate the area float area = (s * (s - 4) * (s - 5) * (s - 3)); // take the square root float result = sqrt(area); // Print the result printf("The area of the triangle with sides 4, 5 and 3 is %f", result); // Output: The area o [instruction] | Find the area of a triangle whose sides measure a= 4, b= 5 and c= 3. [input] |

[output] | # define the query query = "SELECT * FROM people WHERE name = %s AND age = %s" # provide the parameters params = ('John', 22) # execute the query cursor.execute(query, params) [instruction] | Create a parameterized query in Python to find the details of a person. [input] |

[output] | arr = [1, 2, 3, 4, 10, 6] [instruction] | Edit the following code so that the item at index 4 is multiplied by two. [input] | arr = [1, 2, 3, 4, 5, 6]

[output] | class PriorityQueue(): def __init__(self): self.elements = [] def insert(self, item, priority): self.elements.append((priority, item)) def pop(self): _, item = heappop(self.elements) return item [instruction] | Make the following piece of code functional for priority queues. [input] | class PriorityQueue(): #TODO

[output] | def remove_repeats(lst): new_lst = [] for item in lst: if item not in new_lst: new_lst.append(item) return new_lst [instruction] | Create a function that removes all the repeated elements from a list. [input] | lst = [3, 5, 1, 3, 7, 5]

[output] | def factorial(n): if n == 0 or n == 1: return 1 else: return n * factorial(n-1) [instruction] | Convert the following function into a recursive version. [input] | def factorial(n): result = 1 for i in range(1, n+1): result *= i return result

[output] | from networkx import nx G = nx.Graph() G.add_nodes_from(nodes) for link in links: G.add_edge(link[0], link[1]) [instruction] | Create a network topology using the following input. [input] | nodes = ['A', 'B', 'C', 'D', 'E'] links = [('A', 'B'), ('B', 'C'), ('D', 'E'),('E', 'D')]

[output] | def clean_binary_data(binary_data): return ''.join(map(lambda x:chr(x) if 32 <= x <= 126 else '', binary_data)) [instruction] | Design a function to clean binary data (strings) by keeping only printable characters. [input] | binary_data = b'h\x9Fl\x04o'

[output] | import threading x = 0 lock = threading.Lock() def incrementer(): global x with lock: x += 1 return x [instruction] | Make the following code work in a multithreading environment. [input] | x = 0 def incrementer(): #TODO

[output] | var items = ['item1', 'item2', 'item3', 'item4', 'item5']; [instruction] | Suggest a way to store a list of five items in a JavaScript variable. [input] |

[output] | document.getElementById("myParagraph").innerHTML = "Goodbye, World!"; [instruction] | Write a JavaScript that changes the text of a paragraph element, from "Hello, World!" to "Goodbye, World!" [input] |

[output] | alert("Hello, World!"); [instruction] | Suggest a way to display an alert message with the text "Hello, World!". [input] |

[output] | SELECT * FROM Student WHERE Grade >= 90; [instruction] | Construct an SQL query to select all students who have a grade of 90 or greater from the 'Student' table. [input] |

[output] | Event listeners can be used to make the page interactive. For example, onclick listeners could be used to execute functions when a button is clicked, onsubmit listeners could be used to execute functions when a form is submitted, and onchange listeners could be used to execute functions when an elem [instruction] | Suggest a way to create an interactive web page using HTML and JavaScript. [input] |

[output] | def pyramid_to_num(pyramid): num = 0 val = 0 for line in pyramid: val = int(line[0]) * 10**(len(line) - 1) num += val * 2**len(line) return num # Test pyramid = [['9'],['2', '3'],['9', '3', '5'],['1', '8', '6', '8']] print(pyramid_to_num(pyramid)) [instruction] | Convert pyramid of numbers to a single number. [input] | 9 2 3 9 3 5 1 8 6 8

[output] | """ Get an array of all the h2 elements on a page """ from bs4 import BeautifulSoup # Input HTML html = """ <html> <body> <h1>This is a Heading</h1> <h2>This is a Sub Heading</h2> <h2>This is another Sub Heading</h2> </body> </html> """ # Parse the HTML and create [instruction] | For the given HTML page, create an array of all the h2 elements on the page. [input] | <html> <body> <h1>This is a Heading</h1> <h2>This is a Sub Heading</h2> <h2>This is another Sub Heading</h2> </body> </html>

[output] | """ Process a JavaScript object and produce a string of its properties in alphabetical order """ const obj = { name: 'John Doe', age: 40, address: { street: '123 Main Street', city: 'Albany', state: 'NY', }, }; const objKeys = Object.keys(obj); // Sort objKeys in alphabetical [instruction] | Process the given JavaScript object and produce a string of the object's properties in alphabetical order. [input] | const obj = { name: 'John Doe', age: 40, address: { street: '123 Main Street', city: 'Albany', state: 'NY', }, };

[output] | """ Modify the code to display a simple error message whenever a parameter is passed as string """ function sum(a, b) { // Test if either a or b is a string if (typeof a === 'string' || typeof b === 'string') { throw new Error('Parameters must be numbers'); } return a + b; } [instruction] | Modify the code to display a simple error message whenever a parameter is passed as string. [input] | function sum(a, b) { return a + b; }

[output] | """ Edit the code to make the string word_list case-insensitive """ word_list = ["cat", "dog", "bird"] # Make the string case-insensitive word_list = [word.lower() for word in word_list] print(word_list) """ Output: ['cat', 'dog', 'bird'] """ [instruction] | Edit the code to make the string word_list case-insensitive. [input] | word_list = ["cat", "dog", "bird"]

[output] | """ Resolve the issue in the code causing a TypeError to be thrown """ names = ["John", "James", 10] for name in names: # Check the type of the element and only display it if it's a string if type(name) == str: print(name) """ Output: John James """ [instruction] | Resolve the issue in the code causing a "TypeError" to be thrown [input] | names = ["John", "James", 10] for name in names: print(name)

[output] | """ For the given dictionary, list all its keys and values in the following format """ data = { "name": "John Doe", "age": 40, "address": { "street": "123 Main Street", "city": "Albany", "state": "NY" } } for key, value in data.items(): print(f"{key}: {value}") if isins [instruction] | For the given Python dictionary, list all its keys and values in the following format. [input] | { "name": "John Doe", "age": 40, "address": { "street": "123 Main Street", "city": "Albany", "state": "NY" } }

[output] | """ Generate a JSON response which contains the age of all users in the database """ import json # Database of users users = [ {'name': 'John Doe', 'age': 40}, {'name': 'Bob Jones', 'age': 30}, {'name': 'Alice Smith', 'age': 20} ] # Generate the json response response = {'ages': [user['age [instruction] | Generate a JSON response which contains the age of all users in the database. [input] |

[output] | """ Return an array which contains all the words of the given string in reverse order """ string = "This is a test sentence." # Split the string into a list words = string.split(' ') # Reverse the list of words reversed_words = words[::-1] # Construct the output array output_array = [word[::-1] [instruction] | Return an array which contains all the words of the given string in reverse order. [input] | string = "This is a test sentence."

[output] | # Create a Dictionary dict = { "India" : ["Delhi", "Mumbai", "Chennai"], "USA" : ["New York", "Washington", "Los Angeles"], "Canada" : ["Toronto", "Vancouver", "Ottawa"], "France" : ["Paris", "Marseille", "Lyon"] } # Print the Dictionary print(dict) [instruction] | Create a dictionary in Python and store the names of four countries and the cities within them. [input] |

[output] | .text { font-family: Arial; font-size: 20px; font-weight: bold; } [instruction] | Write a CSS style that changes the text size to 20px, makes the text bold, and changes the font to Arial. [input] |

[output] | SELECT name FROM students WHERE grade >= 80; [instruction] | Write an SQL query to retrieve the names of students in a class with a grade of 80 or above. [input] |

[output] | // Create a `div` element let divElement = document.createElement('div'); // Create a `p` element let pElement = document.createElement('p'); // Add the content to the `p` element pElement.textContent = 'Hello, World!'; // Append the `p` element to the `div` element divElement.appendChild(pEleme [instruction] | Convert the HTML code below to its corresponding DOM elements. [input] | <div> <p>Hello, World!</p> </div>

[output] | result = (x > 0) ? "Yes" : "No" console.log(result) // Output: Yes [instruction] | Use a ternary operator to print "Yes" if the number is positive and "No" if the number is negative. [input] | x=3

[output] | def frequencySort(arr): eleFreq = {} sortedList = [] # Create a dictionary with frequency of element as key and element as value for i in arr: if i in eleFreq: eleFreq[i] += 1 else: eleFreq[i] = 1 # Sort the dictionary sort [instruction] | Write a function to sort the elements of a list based on their frequency. [input] | arr = [2, 5, 9, 8, 8, 5, 9, 2]

← → 방향키로 페이지 이동 · 숫자 입력 후 Enter로 점프