← 목록

Synth · CodeAlpaca일부

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

[output] | def find_largest(array): largest = array[0] for x in array: if x > largest: largest = x return largest [instruction] | Using the given code, write a function that finds the highest value in the array. [input] | array = [5, 2, 8, 7, 1]

[output] | // JavaScript Code let list = []; const addToList = (str) => { list.push(str); } const createList = () => { let html = "<ul>\n"; for(let i = 0; i < list.length; i++) { html += `<li>${list[i]}</li>\n`; } html += "</ul>"; document.getElementById('list').innerHTML = html; } [instruction] | Using JavaScript, create an interactive web page that displays a list of strings taken from the user's inputs. [input] |

[output] | // JavaScript Code function flattenKeys(obj) { let flattened = {}; for (let key in obj) { if (typeof obj[key] === 'object') { for (let subkey in obj[key]) { flattened[`${key}_${subkey}`] = obj[key][subkey]; } } else { flattened[key] = obj[key]; } } return flattened; } [instruction] | Given a JSON object, write a JavaScript function to flatten the object keys. [input] | { "name": { "first": "John", "last": "Smith" }, "age": 25 }

[output] | def get_word_frequency(string): words = string.split(', ') frequencies = {} for word in words: if word in frequencies: frequencies[word] += 1 else: frequencies[word] = 1 return frequencies [instruction] | Create a Python program that takes a comma-separated string and outputs a dictionary of words and the frequency of their occurrences. [input] | apple, banana, apple, orange

[output] | // JavaScript Code function checkAnagrams(str1, str2) { const s1 = str1.split('').sort().join(''); const s2 = str2.split('').sort().join(''); return s1 === s2; } [instruction] | Using JavaScript, create a program to check whether two given strings are an anagram or not. [input] |

[output] | def sum_areas(circles): total = 0 for circle in circles: area = 3.14 * circle['radius'] ** 2 total += area return total [instruction] | Write a Python function to calculate the sum of the areas of a given list of circles, where each circle is defined as a dictionary containing 'radius' and 'x' as keys. [input] | [{'radius': 3, 'x': 5}, {'radius': 4, 'x': 7}, {'radius': 5, 'x': 9}]

[output] | SELECT * FROM products ORDER BY price ASC; [instruction] | Write an SQL query to sort a table named 'products' based on the price in ascending order. [input] |

[output] | // Java Code public class MaximumSubArraySum { public static int maxSubArraySum(int[] nums) { int maxSum = Integer.MIN_VALUE; int currentSum = 0; for (int num : nums) { currentSum += num; if (currentSum > maxSum) maxSum = currentSum; if (currentSum < 0) currentSum = 0; } return maxSum; [instruction] | Using Java, create a program to find the maximum sum of a sub-array within a given array. [input] |

[output] | def delete_key(d, key): if key in d: del d[key] d = {'a':1, 'b':2} delete_key(d, 'a') [instruction] | Write a Python program to delete a given key from a dictionary. [input] |

[output] | class Vector2D { private: int x; int y; public: Vector2D(int x, int y); int GetX() { return x; } int GetY() { return y; } void SetX(int newX) { x = newX; } void SetY(int newY) { y = newY; } }; Vector2D::Vector2D(int x, int y) { this-> [instruction] | Create a class in C++ representing a 2D vector which has components (x, y). [input] |

[output] | public class StudentRecord { private String studentName; private int grade; private double score; public StudentRecord(String studentName, int grade, double score) { this.studentName = studentName; this.grade = grade; this.score = score; } public String getStudentName() { return stud [instruction] | Write a Java class to represent a student record with a student_name, grade and score fields. [input] |

[output] | { "_id": ObjectID( 0000000001 ), "name": "John Doe", "city": "New York", "phone": "123-456-7890", "address": "123 Main Street" } [instruction] | Design a MongoDB database with a customers collection which contains the following fields: name, city, phone, and address. [input] |

[output] | CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY, first_name VARCHAR(255), email VARCHAR(255) UNIQUE NOT NULL ); CREATE TABLE products ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), price NUMERIC ); CREATE TABLE orders ( id INT AUTO_INCREMENT PRIMARY KEY, user_id INT NOT NUL [instruction] | Create a database structure in MySQL for a shopping cart application containing a user, product and order table. [input] |

[output] | SELECT CustomerName, SUM(TotalPrice) AS TotalSpend FROM Orders GROUP BY CustomerName ORDER BY TotalSpend DESC LIMIT 3; [instruction] | Design a SQL query to find the top 3 customers with the highest spendings. [input] |

[output] | SELECT MAX(name, age) AS OldestCustomer, MIN(name, age) AS YoungestCustomer FROM Customers GROUP BY age; [instruction] | Create a SQLite query to find the names and ages of the youngest and oldest customers. [input] |

[output] | function partitionArray(arr) { const evenArr = []; const oddArr = []; for (let i = 0; i < arr.length; i++) { if (arr[i] % 2 == 0) { evenArr.push(arr[i]); } else { oddArr.push(arr[i]); } } return [evenArr, oddArr]; } [instruction] | Write a function in JavaScript to partition the array into even and odd numbers. [input] |

[output] | public class Circle2D { private double radius; public Circle2D() { radius = 0; } public Circle2D(double radius) { this.radius = radius; } public double getRadius() { return radius; } public void setRadius(double radius) { [instruction] | Create a class in C# to represent a 2D circle which has a radius field. [input] |

[output] | def get_grade(marks): if marks>=90: return "A" elif marks>=80 and marks<90: return "B" elif marks>=70 and marks<80: return "C" elif marks>=60 and marks<70: return "D" else: return "F" print(get_grade(marks)) [instruction] | Implement a function in Python that prints out the grade for a student, given their marks in a particular subject. [input] | marks = 90

[output] | <form> <label>Name: </label> <input type="text" id="name" name="name"> </form> [instruction] | Create a function in HTML that creates a text box element with the given label. [input] | label = "Name: "

[output] | public static int factorial(int num){ if (num == 0){ return 1; } else{ int factorial = num * factorial(num - 1); return factorial; } } [instruction] | Develop a function in Java that, given a positive number, returns the factorial of that number. [input] | num = 5

[output] | def letter_frequency(text): d = {} for char in text: if char not in d: d[char] = 1 else: d[char] += 1 return d print(letter_frequency(text)) [instruction] | Write a function that, given a string, returns a dictionary of all the characters in the string and their respective frequencies. [input] | text = "Hello World"

[output] | CREATE TABLE cities ( city_id INT AUTO_INCREMENT PRIMARY KEY, city_name VARCHAR(255) NOT NULL, population INT NOT NULL, country VARCHAR(255), area INT ); [instruction] | Design a MySQL table of 10 rows to store information about cities. [input] |

[output] | public static double mean(int[] numbers) { double sum = 0.0; for (int i = 0; i < numbers.length; i++) sum += numbers[i]; return sum / numbers.length; } [instruction] | Code a calculation to find the mean of numbers stored in an array in Java. [input] | numbers = {1, 2, 3, 4, 5}

[output] | <?php for ($i=1; $i<=10; $i++){ $rand_num = rand(0, 10); echo $rand_num . "\n"; } ?> [instruction] | Use a for-loop in PHP to generate a random number between 0 and 10. [input] |

[output] | import re def find_capital_letter(text): pattern = r"[A-Z]" result = re.findall(pattern, text) return result[0] print(find_capital_letter(text)) [instruction] | Use a regular expression to find the capital letter in the provided string. [input] | text = "This is a string with a Capital A"

[output] | def sum_of_squares(n): total_sum = 0 for i in range(n + 1): total_sum += i ** 2 return total_sum [instruction] | Create a method to compute the sum of squares of numbers from 0 up to n. [input] | n = 4

[output] | def find_mode(nums): mode = 0 max_occurrence = 0 for num in nums: occurrences = nums.count(num) if occurrences > max_occurrence: max_occurrence = occurrences mode = num return mode [instruction] | How would you write a function to find the mode in an array of numbers? [input] | nums = [2, 3, 4, 5, 5, 6, 7, 8]

[output] | def calc_fibonacci_number(index): if index == 0 or index == 1: return index first_num = 0 second_num = 1 for i in range(2, index+1): next_num = first_num + second_num first_num, second_num = second_num, next_num return second_num [instruction] | Create a function to calculate Fibonacci sequence number based on the index of the number. [input] | index = 6

[output] | class PrimeCalculator: def __init__(self, n): self.n = n def get_primes(self): primes = [] for number in range(2, self.n+1): is_prime = True for divisor in range(2, number): if number % divisor == 0: is_ [instruction] | Generate a python class for calculating prime numbers up to n. [input] | n = 10

[output] | def linear_search(list, key): for index, value in enumerate(list): if value == key: return index return -1 [instruction] | Implement a linear search in a list. [input] | list = [1, 5, 9, 10]

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