← 목록

Synth · CodeAlpaca일부

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

[output] | for (int i = 1; i <= 10; i++) { System.out.print(i + " "); } [instruction] | Write a for-loop in Java for printing the numbers from 1 to 10 with a space separating each number. [input] |

[output] | int sum = 0; for(int i = 0; i < numbers.length; i++) { sum += numbers[i]; } [instruction] | In C#, write a loop to sum up a given array of numbers. [input] | int[] numbers = {1, 2, 3, 4, 5};

[output] | One possible solution would involve creating a program that takes a list of purchased items and calculates the average price of the product. The program could take the following steps: 1. Sum the prices of all items in the list. 2. Divide the sum by the number of items in the list. 3. Output the ave [instruction] | Proposition some ideas for a C++ program to calculate the average price of a product given its list of purchased items. [input] |

[output] | One possible solution would be to use a variation of the bubble sort algorithm, where the elements are being swapped from the last element to the first element. def sort_numbers_descending(elements): n = len(elements) # Traverse through all elements for i in range(n-1): # Last i elements [instruction] | Propose an algorithm in Python for sorting a given list of numbers in descending order. [input] |

[output] | The main difference between sets and lists in Python is the way the elements are stored. Lists store the elements in an ordered sequence, whereas sets store the elements in an unordered set. Sets are faster in terms of performance because they do not have duplicate elements. This means that when che [instruction] | Explain in plain English the difference between the set() and list() methods in Python. [input] |

[output] | <!DOCTYPE html> <html> <head> <title>Shopping Cart</title> <style> body { margin: 0px; } #container { width: 100%; height: 100%; display: flex; flex-direction: column; } #header { height: 100px; background-color: #eee; display: flex; align-items: center; [instruction] | Create a basic UI in HTML/CSS for a shopping cart website. [input] |

[output] | public static int recursive(int n) { if (n == 0) { return 0; } else { return n + recursive(n - 1); } } [instruction] | Rewrite the following recursive algorithm in Java. def recursive(n): if n == 0: return 0 else: return n + recursive(n-1) [input] |

[output] | <?php function generateRandomString($length = 10) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)] [instruction] | Write a script in PHP for generating a random alphanumeric string of length 10. [input] |

[output] | package main import ( "fmt" "strings" ) func CountWords(str string) int { return len(strings.Fields(str)) } func main() { result := CountWords("The quick brown fox jumps over the lazy dog") fmt.Println(result) // Output: 9 } [instruction] | Create an API in Go that takes a string and returns the amount of words present in the given string. [input] |

[output] | class Arithmetic def add(x, y) x + y end def subtract(x, y) x - y end def multiply(x, y) x * y end def divide(x, y) x.to_f / y end end [instruction] | Write a class in Ruby that implements the following methods: `add`, `subtract`, `multiply`, and `divide`. [input] |

[output] | def find_pair(arr,k): pairs = [] found_elements = set() for num in arr: diff = k - num if diff in found_elements: pairs.append([min(num,diff), max(num,diff)]) found_elements.add(num) return pairs [instruction] | Create a function in Python to find all pairs of integers that sum up to k. [input] |

[output] | #include <iostream> #include <algorithm> using namespace std; void mostFrequent(int arr[], int n) { sort(arr, arr + n); int max_count = 1, res = arr[0], curr_count = 1; for (int i = 1; i < n; i++) { if (arr[i] == arr[i - 1]) curr_count++; else [instruction] | Write a C++ program that reads in a series of integers and prints out the most frequent. [input] |

[output] | def singleOccurence(arr): ans = [] for i in range(len(arr)): count = 0 for j in range(len(arr)): if arr[i] == arr[j]: count+=1 if count == 1: ans.append(arr[i]) return ans [instruction] | Design an algorithm in Python to retrieve all elements in a given array that occur only once. [input] |

[output] | function filterBiggerThan(arr, num) { return arr.filter(n => n > num); } [instruction] | Create a program in Javascript that takes an array of numbers and an integer and returns an array containing only the numbers that are larger than the given integer. [input] | Array of numbers: [4, 8, 12, 7, 3] Integer: 7

[output] | def sort_array(arr): for i in range(len(arr) - 1): min_index = i for j in range(i + 1, len(arr)): if arr[j] < arr[min_index]: min_index = j arr[i], arr[min_index] = arr[min_index], arr[i] # swap return arr [instruction] | Create a sorting algorithm to order a given array. [input] | [ 2 , 8 , 3 , 10 , 16 ]

[output] | x = 5 y = 3 result = x + y print(result) [instruction] | Represent the following expression using a program [input] | x = 5, y = 3

[output] | def check_order(arr): order = 0 if arr[0] < arr[1]: order = 1 elif arr[0] > arr[1]: order = -1 for i in range(1, len(arr)-1): if arr[i] > arr[i+1] and order == 1: return 0 elif arr[i] < arr[i+1] and order == -1: retu [instruction] | How can you use a function to determine whether a given array is in increasing or decreasing order or unordered? [input] |

[output] | mydict = {'a':1, 'b':2, 'c':3} [instruction] | Create a Python dictionary object [input] | {'a':1, 'b':2, 'c':3}

[output] | public class Pattern { public static void main(String[] args) { for (int i = 1; i <= 4; i++) { for (int j = 1; j <= i; j++ ) System.out.print("*"); System.out.println(); } } } [instruction] | Write a Java program to generate the following patterns using a for loop. * ** *** **** [input] |

[output] | function clone(obj) { let cloneobj = {}; for (let key in obj) { if (obj.hasOwnProperty(key)) { cloneobj[key] = obj[key]; } } return cloneobj; } [instruction] | Write a JavaScript program to clone a given object. [input] |

[output] | def greater(list, argument): output = [] for int in list: if int > argument: output.append(int) return output [instruction] | Write a function which takes a list and an additional argument, and returns the elements of the list which are greater than the argument. [input] | list = [10, 20, 30, 40, 50, 60] argument = 25

[output] | SELECT customers.name FROM customers INNER JOIN orders ON customers.id = orders.customer_id [instruction] | Write a query to retrieve the names of customers from the Customers table who have orders in the Orders table. [input] |

[output] | def sum_numbers(lst): sum = 0 for item in lst: if type(item) == int or type(item) == float: sum += item return sum [instruction] | Write a function which takes in a list containing integers, strings and floats and returns the sum of all numbers in the list. [input] | list = [2, 'John', 8.2, 3.4, 11]

[output] | SELECT customers.name, SUM(items.price * orders.quantity) AS total FROM customers INNER JOIN orders ON customers.id = orders.customer_id INNER JOIN items ON orders.item_id = items.id GROUP BY customers.name [instruction] | Write a query to list the names and total order amount of customers who have purchased any item from the Items table. [input] |

[output] | import tkinter as tk root = tk.Tk() tk.Label(root, text='Hello World!').pack() tk.Button(root, text="Click Me!").pack() root.mainloop() [instruction] | Create a GUI that displays text and a button. [input] |

[output] | CREATE TABLE User ( user_id int NOT NULL AUTO_INCREMENT PRIMARY KEY, name varchar(50) NOT NULL, mobile_number varchar(20) NOT NULL ); [instruction] | Create a mySQL script to create a table called "User" with columns user_id, name, and mobile_number? [input] |

[output] | SELECT COUNT(*) FROM customers c WHERE c.age > 20; [instruction] | Write a SQL query to find the count of all customers whose age is more than 20? [input] |

[output] | def remove_punctuation(sentence): punctuation_marks = '''!()-[]{};:'"\,<>./?@#$%^&*_~''' new_sentence = "" for char in sentence: if char not in punctuation_marks: new_sentence += char return new_sentence [instruction] | Write a Python function to remove punctuation from a given sentence. [input] | The quick brown fox jumps over the lazy dog!

[output] | def find_sum_target(nums, target): for i in range(len(nums) - 1): for j in range(i+1, len(nums)): if nums[i] + nums[j] == target: return [nums[i], nums[j]] return [] [instruction] | Given a list of positive integers, write a program to find two elements whose sum equals a given target value. [input] | [1, 2, 3, 4, 5], 4

[output] | def generate_fibonacci(n): fibonacci_list = [0, 1] for i in range(2, n+1): fibonacci_list.append(fibonacci_list[i-2] + fibonacci_list[i-1]) return fibonacci_list [instruction] | Write a Python function to generate a list of Fibonacci numbers up to the given limit n. [input] |

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