← 목록

Synth · CodeAlpaca일부

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

[output] | localStorage.setItem('key', 'value'); [instruction] | Create a JavaScript code snippet to store a string value in localStorage. [input] |

[output] | SELECT p.product_id, p.name, p.description, p.price FROM products p LEFT JOIN order_items oi ON p.product_id = oi.product_id WHERE oi.product_id IS NULL [instruction] | Write an SQL query to find the products which have not been ordered by any customers. [input] | TABLE products Columns: * product_id * name * description * price TABLE order_items Columns: * order_item_id * order_id * product_id

[output] | def sum_multiples_of_3_and_5(n): sum = 0 for i in range(1, n+1): if i % 3 == 0 or i % 5 == 0: sum += i return sum [instruction] | Write a Python program to calculate the sum of all multiples of 3 and 5 between 1 and a given number. [input] |

[output] | a { font-size: 16px; color: green; } [instruction] | Write a CSS code snippet to set the default font size to 16px and color to green for all links. [input] |

[output] | One way to classify text documents into a certain number of topics is to use latent Dirichlet allocation (LDA). LDA is a generative statistical model that allows for documents to be modeled as a mixture of topics. It fits well when documents are short and there is a large number of topics to be iden [instruction] | Suggest a way to classify text documents into a certain number of topics. [input] |

[output] | public static void FindRoots(double a, double b, double c) { double discriminant = b * b - 4 * a * c; // condition for real and different roots if (discriminant > 0) { double root1 = (-b + Math.Sqrt(discriminant)) / (2 * a); double root2 = (-b - Math.Sqrt(discriminant)) / (2 [instruction] | Create a user-defined function in C# to find the roots of a second-order polynomial. [input] |

[output] | Algorithm for sorting a single-linked list: 1. Traverse the list and find the minimum value. 2. Save the pointer to this minimum element. 3. Move this minimum element to the start of the list and make it the head node. 4. Set the pointer to the last minimum element to point to the next element. 5. [instruction] | Write an algorithm for sorting a single-linked list. [input] |

[output] | Garbage collection in Java works by periodically running a garbage collector to identify and reclaim memory occupied by objects that are no longer referenced. This process is done in order to free the memory for use by other objects and to prevent memory leaks. The Java Virtual Machine implements th [instruction] | Explain how garbage collection works in Java. [input] |

[output] | public static String convertTimeStampToDateTime(long timestamp) { Date date = new Date(timestamp * 1000L); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); return sdf.format(date); } [instruction] | Create a function in Java to convert a given timestamp into readable date and time. [input] | 1586714115

[output] | public static int countCharacterOccurrences(String s, char c) { int count = 0; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == c) count++; } return count; } [instruction] | Write the code for counting the number of occurrences of a character in a given string. [input] | String: "Hello World" Character: 'l'

[output] | Algorithm for implementing a stack with two queues: 1. Create two queues and enqueue the element to the first queue. 2. Dequeue an element from the first queue, and enqueue it again to the second queue. 3. Now, enqueue the next element from the first queue to the first queue. 4. Repeat steps 2 and [instruction] | Suggest an algorithm to implement a stack with two queues. [input] |

[output] | import sys if sys.version_info.major == 3: input = int(input('Enter your number: ')) else: input = int(raw_input('Enter your number: ')) [instruction] | Convert a code written in Python 3 into code compatible with Python 2. [input] | input = int(input('Enter your number: '))

[output] | def add_two_numbers(nums): if nums[0] == nums[1]: return nums[0] else: return nums[0] + nums[1] [instruction] | Update the code to handle cases when the two numbers in the array are the same. [input] | def add_two_numbers(nums): return nums[0] + nums[1]

[output] | def square_sum(x, y): return x * x + y * y # Break down code # part 1 def square_sum(x, y): # part 2 return x * x + y * y # part 3 # return calculated value [instruction] | Break down the given code into its individual parts. [input] | def square_sum(x, y): return x*x + y*y

[output] | def print_even_odd(number): if number % 2 == 0: print("even") else: print("odd") [instruction] | Write a Python function which takes a number as an argument and print "even" if the number is even and print "odd" if the number is odd. [input] |

[output] | def calculate_area(length, width, height): return 0.5 * (length * width + length * height + width * height) [instruction] | Add a parameter to the function to calculate the area of a triangle. [input] | def calculate_area(length, width): return length * width

[output] | def find_min(arr): return min(arr) [instruction] | Rewrite the code to be more concise and efficient. [input] | def find_min(arr): min_val = float('inf') for i in arr: if i < min_val: min_val = i return min_val

[output] | src_code = """if x == 1: print "hello" if y == 2: print "world" print "!" # updated code lines = src_code.splitlines() for line in lines: if "print" in line: print(line) [instruction] | Update the code so that it only prints out the lines which contain the word “print”. [input] | src_code = """if x == 1: print "hello" if y == 2: print "world" print "!"

[output] | def age_calc(age): if not isinstance(age, int): raise TypeError("Input for age calculation must be int") return age + 5 [instruction] | Update the code to ensure that an error is raised if the input is the wrong type. [input] | def age_calc(age): return age + 5

[output] | """ Compute a factorial of a given integer """ def factorial(n): if n == 0: return 1 else: return n * factorial(n-1) if __name__ == '__main__': n = int(input()) print(factorial(n)) [instruction] | Compute a factorial of a given integer. [input] | 5

[output] | """ Function which takes two numbers as arguments and returns their sum """ def add_numbers(x, y): return x + y if __name__ == '__main__': x = int(input()) y = int(input()) print(add_numbers(x, y)) [instruction] | Make a function which takes two numbers as arguments and returns their sum. [input] |

[output] | """ Implement a Wiki page title search using Python """ import wikipedia def search_wiki_title(search_string): try: wikipedia.set_lang("en") result = wikipedia.search(search_string)[0] except (wikipedia.exceptions.PageError, wikipedia.exceptions.DisambiguationError): [instruction] | Implement a Wiki page title search using Python. [input] | Search string: "Machine Learning"

[output] | """ Write a function to find the average of given numbers using a list """ def find_average(nums): return sum(nums) / len(nums) if __name__ == '__main__': nums = [2, 4, 6, 8] print(find_average(nums)) [instruction] | Write a function to find the average of given numbers using a list. [input] | nums = [2, 4, 6, 8]

[output] | """ Parse an HTML table and extract all the rows. """ import re def get_table_rows(html): pattern = re.compile('<tr>(.*?)</tr>', re.DOTALL) rows = re.findall(pattern, html) return rows if __name__ == '__main__': html = """ <table> <tr> <td>Row 1 - Column 1< [instruction] | Parse an HTML table and extract all the rows. [input] | <table> <tr> <td>Row 1 - Column 1</td> <td>Row 1 - Column 2</td> </tr> <tr> <td>Row 2 - Column 1</td> <td>Row 2 - Column 2</td> </tr> </table>

[output] | def binary_search(nums, target): left, right = 0, len(nums) - 1 while left <= right: mid = (left + right) // 2 if nums[mid] == target: return mid elif nums[mid] > target: right = mid - 1 else: left = mid + 1 return -1 # [instruction] | Create a function to do a binary search on a sorted list of integers. [input] | nums = [2, 4, 5, 7, 8, 9, 10, 14]

[output] | count = 0 # to count the number of prime numbers for num in range(1,100): # all prime numbers are greater than 1 if num > 1: for i in range(2,num): if (num % i) == 0: break else: print(num) count += 1 if count == 5: [instruction] | Develop a for loop to write a program to print the first 5 prime numbers [input] |

[output] | A for loop is a programming structure used to repeat a specific set of instructions for a given number of times or until a specified condition is met. The syntax of a for loop is "for <variable> in <sequence>:" and the format is "for <variable> in range(<start_value>, <end_value>):" where the start [instruction] | What is a for loop? [input] |

[output] | The yield keyword in Python is used to create an iterator. When a function containing yield is called, it does not execute the code as a normal function would, instead it returns a generator object which is an iterator. Each time next() is called on the iterator, the yield statement is executed and [instruction] | Explain what the yield keyword does in Python. [input] |

[output] | A try-except block in Python allows a code block to be tested for errors. The code that could potentially cause an exception is placed in the try clause and the code that handles the exception is put in the except clause. If an error is encountered in the try clause, the program execution is transfe [instruction] | How does a try-except block work in Python? [input] |

[output] | SELECT SUM(Salary) FROM Employee; [instruction] | Using SQL, write a query to find the total salary of employees in the Employee table [input] | Table: | EmployeeID | Name | Salary | |------------|-------|--------| | 1 | John | 1000 | | 2 | David | 2000 | | 3 | Mark | 1500 |

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