← 목록

Synth · CodeAlpaca일부

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

[output] | def greatest_common_divisor(n1, n2): while n2 > 0: n1, n2 = n2, n1 % n2 return n1 result = greatest_common_divisor(18, 15) print(result) // Output: 3 [instruction] | Write a function in Python that returns the greatest common divisor (GCD) of two numbers. [input] | n1 = 18, n2 = 15

[output] | def bubbleSort(arr): n = len(arr) for i in range(n): for j in range(0, n-i-1): if arr[j] > arr[j+1] : arr[j], arr[j+1] = arr[j+1], arr[j] return arr sorted_arr = bubbleSort(arr) print(sorted_arr) // Output: [1.6, 2.1, 2.5, 3.2, 4.6] [instruction] | You are given a list of float numbers. Write a code to sort them in ascending order. [input] | arr = [2.5, 3.2, 2.1, 4.6, 1.6]

[output] | def twoSum(nums, target): result = [] for i in range(len(nums)): for j in range(i+1, len(nums)): if nums[i]+nums[j] == target: result.append(i) result.append(j) return result indices = twoSum(nums, 9) print(indices) // Output: [0, 2] [instruction] | Given an array of integers, write a method to return the indices of the two numbers such that they add up to a specific target. [input] | nums = [2, 5, 11, 15], target = 9

[output] | import string import random def generate_password(): alpha_list = list(string.ascii_letters) + list(string.digits) return ''.join([random.choice(alpha_list) for _ in range(8)]) random_password = generate_password() print(random_password) // Output: 4U4K5U6L [instruction] | Write a code that generates a random password of 8 characters including numerical and alphabetic characters. [input] |

[output] | SELECT c.customer_name, MAX(o.order_date) FROM customer c LEFT JOIN orders o ON c.customer_id = o.order_id GROUP BY c.customer_name ORDER BY o.order_date DESC; [instruction] | Write a SQL query to list all the customers in the customer table in descending order for the most recent order. [input] |

[output] | # The Purpose of this Project The purpose of this project is to create a user-friendly program for calculating the **area of a circle**. [instruction] | Format the following text using Markdown. [input] | The purpose of this project is to create a user-friendly program for calculating the area of a circle.

[output] | ^(.*\bapple\b.*)$ [instruction] | Generate a regular expression to check for the presence of word ‘apple’ [input] |

[output] | def multiply(a, b): """Returns the product of the two parameters.""" return a * b [instruction] | Format the following code using a linter [input] | func multiply(a,b) { return a*b }

[output] | DELETE FROM Employee; [instruction] | Generate a valid SQL query to delete all the records from ‘Employee’ Table [input] |

[output] | def compare_dates(date1, date2): if date1 > date2: return 1 elif date1 == date2: return 0; else: return -1 [instruction] | Generate a correct code to compare two date objects [input] |

[output] | def filter_by_search_term(strings, search_term): return [string for string in strings if search_term in string] [instruction] | Write a function to filter a list of strings based on a search term [input] |

[output] | def print_hello(): print('Hello World!') [instruction] | Update the function to print ‘Hello World!’ [input] | def print_hello(): print('Hello')

[output] | mydict = {} for key, value in mydict.items(): if value not in mydict.values(): mydict[key]=value [instruction] | Update the following code snippet to ensure that the values in the dictionary are unique. [input] | mydict = {"a":1, "b":2, "c":3, "d":4, "e":5}

[output] | ^\d*\.\d{3}$ [instruction] | Create a regular expression to match numbers with exactly three decimal places. [input] |

[output] | def convert12to24(time12h): # Check if last two elements of time is AM and first two are 12 if time12h[-2:] == "AM" and time12h[:2] == "12": return "00" + time12h[2:-2] # If last two elements of time is AM elif time12h[-2:] == "AM": return time12h[:-2] [instruction] | Create a function in Python to convert time from 12 hour to 24 hour format. [input] |

[output] | def print_list(list): for i in list: if i%2==0: print(i) [instruction] | Update the following function to only print the even numbers in a given list [input] | def print_list(list): for i in list: print(i)

[output] | function sortList(arr) { return arr.sort((a, b) => a - b); } [instruction] | Create a JavaScript program to sort a given list in ascending order. [input] |

[output] | The 'enumerate' keyword is used to iterate over an iterable and keep track of the index along the way. Its syntax is "enumerate(iterable, start=0)". Each iteration yields a tuple containing the index of the element and the element itself. This is most commonly used for loops that need to track the i [instruction] | What is the function of the ‘enumerate’ keyword in Python? [input] |

[output] | The simplest way to find the area of the largest square sub-matrix composed entirely of '1's is to use a dynamic programming approach. The algorithm works by iterating through all the elements in the matrix. At each cell, it checks if the current element is a '1' and if the other elements around it [instruction] | Given a n x n matrix where each element is 0 or 1, how can you find the area of the largest square sub-matrix composed of only ‘1s’? [input] |

[output] | mydict = {x: None for x in set(lst)} print(mydict) # Output: # {1: None, 2: None, 3: None, 4: None, 5: None, 6: None} [instruction] | Create a dictionary from the given list that contains unique elements. [input] | lst = [1, 2, 3, 3, 3, 4, 5, 6, 6]

[output] | A shallow copy of an object creates a new reference to the existing object, while a deep copy creates a new object with a different reference but with the same values. In a shallow copy, changes made to the copied object will be reflected in the original object, whereas with a deep copy, the changes [instruction] | What is the difference between deep copy and shallow copy in Python? [input] |

[output] | age = person['age'] print("The value for the element 'age' is:", age) # Output: The value for the element 'age' is: 32 [instruction] | Using the following dictionary, print the value for the element 'age'. [input] | person = { 'name': 'John Smith', 'age': 32, 'address': '123 Main St.' }

[output] | from bs4 import BeautifulSoup soup = BeautifulSoup(html, 'html.parser') heading = soup.h1.string paragraph = soup.p.string print("Heading:", heading) print("Paragraph:", paragraph) # Output: Heading: This is a heading Paragraph: This is a paragraph. [instruction] | Parse the following HTML using the BeautifulSoup library in Python. [input] | html = '<h1>This is a heading</h1><p>This is a paragraph.</p>'

[output] | str_upper = str.upper() print(str_upper) # Output: THIS IS AN EXAMPLE OF A STRING [instruction] | Change the following string to an upper case. [input] | str = 'this is an example of a string'

[output] | SELECT name FROM employees; [instruction] | Formulate a SQL query to get all the employee names from the 'employees' table. [input] |

[output] | """ Create a TensorFlow model to recognize handwritten numbers """ import tensorflow as tf # Load in the data set mnist = tf.keras.datasets.mnist (x_train, y_train), (x_test, y_test) = mnist.load_data() # Pre-process the data x_train, x_test = x_train / 255.0, x_test / 255.0 # Create the model [instruction] | Create a TensorFlow model to recognize handwritten numbers. [input] |

[output] | public class Fibonacci { public static int[] getFibonacciNumbers(int numTerms) { int[] sequence = new int[numTerms]; int firstTerm = 0, secondTerm = 1; sequence[0] = firstTerm; sequence[1] = secondTerm; for (int i = 2; i < numTerms; i++) { [instruction] | Write a code to find the first 4 terms of the Fibonacci sequence in Java. [input] |

[output] | SELECT job_title, COUNT(*) FROM employees GROUP BY job_title; [instruction] | Write an SQL query to find the counts of all employees grouped by their job titles. [input] |

[output] | import math def calculate_roots(a, b, c): # calculate the discriminant d = (b**2) - (4*a*c) # find two solutions sol1 = (-b-math.sqrt(d))/(2*a) sol2 = (-b+math.sqrt(d))/(2*a) print('The solutions are {0} and {1}'.format(sol1,sol2)) [instruction] | Write a code to calculate the roots of a quadratic equation in Python. [input] |

[output] | CREATE TABLE employees ( id SERIAL PRIMARY KEY, first_name VARCHAR(50) NOT NULL, last_name VARCHAR(50) NOT NULL, job_title VARCHAR(100) NOT NULL, age INTEGER NOT NULL, salary DECIMAL NOT NULL ); [instruction] | Create a new PostgreSQL table named 'employees' with appropriate columns for employee information. [input] |

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