← 목록

Synth · CodeAlpaca일부

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

[output] | def multiply(a, b): return a * b [instruction] | Change the Python code to output the product of two numbers. [input] | def multiply(a, b): return a + b

[output] | def count(list_of_items, item): count = 0 for i in list_of_items: if i == item: count += 1 return count [instruction] | Change the Python code to find the occurrences of an item in a list [input] | def count(list_of_items, item): return len(list_of_items)

[output] | def all_subsets(input_set): res = [[]] for ele in input_set: res += [i + [ele] for i in res] return res [instruction] | Create a program to generate all subsets of a set. [input] | input_set = {1, 2, 3}

[output] | def square(n): return n*n [instruction] | Generate a Python program to generate the square of a number. [input] |

[output] | 0 1 1 2 3 5 8 13 21 34 [instruction] | Output the first 10 Fibonacci numbers. [input] |

[output] | <form action="" method="POST"> <div> <label for="username">Username:</label> <input type="text" name="username" id="username"> </div> <div> <label for="password">Password:</label> <input type="password" name="password" id="password"> </div> <button type="submit">Log In</button> </fo [instruction] | Create a basic login form in HTML. [input] |

[output] | #include <iostream> using namespace std; int largestNumber(int arr[], int n) { int max = arr[0]; for (int i = 0; i < n; i++) { if (arr[i] > max) max = arr[i]; } return max; } int main() { int arr[] = {3, 7, 1, -2, 9, 5}; int [instruction] | Implement an algorithm in C++ for finding the largest number in an array. [input] | int arr[] = {3, 7, 1, -2, 9, 5};

[output] | def create_buckets(arr): buckets = [] x = arr[0] for i in range(1, len(arr)): if arr[i] != x + 1: buckets.append(arr[i-1]) x = arr[i] buckets.append(arr[-1]) return buckets create_buckets([2, 3, 6, 7, 8]) # Output: [2, 3, 6, 8] [instruction] | Create discrete buckets in a given array using the following algorithm. [input] | [2, 3, 6, 7, 8]

[output] | function fibonacci(num) { let a = 1, b = 0, temp; while (num >= 0) { temp = a; a = a + b; b = temp; num--; } return b; } [instruction] | Construct a JavaScript function that implements a fibonacci sequence. [input] |

[output] | def string_formatter(string): new_str = string.split() return ' '.join(new_str) print(string_formatter('This is a string')) # Output: This is a string [instruction] | Fix the following code so it outputs the correct result. [input] | def string_formatter(string): new_str = string.split() return new_str print(string_formatter('This is a string'))

[output] | min = 1 max = 5 average = 3 [instruction] | Find the minimum, maximum, and the average of a list of numbers. [input] | [1, 2, 3, 4, 5]

[output] | public class Student { private String name; private int grade; public void setName(String name) { this.name = name; } public void setGrade(int grade) { this.grade = grade; } public String getName() { return name; } public int getGrade() { return grade; } } [instruction] | Create a class in Java called Student which contains string 'name' and int 'grade'. [input] |

[output] | int_list = [int(i) for i in str_list] # Output: [1, 2, 3, 4] [instruction] | How would you convert this list of strings to integers in Python? [input] | str_list = ['1', '2', '3', '4']

[output] | def find_index(arr, target): for i, num in enumerate(arr): if num == target: return i find_index(arr, target) # Output: 1 [instruction] | Find the position of an element in an array. [input] | arr = [1, 4, 7, 9] target = 4

[output] | """ Debug the following code to print out the result of the polynomial. """ def evaluate_polynomial(coefficients, x): result = 0 for i in range(len(coefficients)): result += coefficients[i] * (x ** (len(coefficients) - i - 1)) return result coefficients = [1, 5, -62] x = 9 pri [instruction] | Debug the following code to print out the result of the polynomial. [input] | polynomial equation: f(x) = x³ + 5x - 62 x = 9

[output] | (123) 456-7890 [instruction] | Detect and output any phone numbers in the give text. [input] | Text: Hello, my name is John and my phone number is (123) 456-7890.

[output] | """ Write a function to make an API call to the Yelp API to return the list of top 10 restaurants near a given address. """ import requests def get_top_10_restaurants(address): endpoint = 'https://api.yelp.com/v3/businesses/search' headers = {'Authorization': 'Bearer your_api_key'} pa [instruction] | Write a function to make an API call to the Yelp API to return the list of top 10 restaurants near a given address. [input] | Address: 1234 Main Street, San Francisco, CA

[output] | """ Write code to print out the numbers up to and including the provided number, starting at 1. """ def print_numbers_up_to(n): for i in range(1, n+1): print(i) if __name__ == '__main__': print_numbers_up_to(10) [instruction] | Write code to print out the numbers up to and including the provided number, starting at 1. [input] | number = 10

[output] | ['11111'] [instruction] | Find the longest substring containing only digits from within the given string. [input] | String: This string contains 11111 and 123456

[output] | import random def generate_random_hex_color_code(): hex_code = "#" for i in range(6): random_digit = random.choice("0123456789ABCDEF") hex_code += random_digit return hex_code if __name__ == '__main__': print(generate_random_hex_color_code()) [instruction] | Create a Python function to generate a random hex color code. [input] |

[output] | """ Train a classification model to classify the sentiment of the given sentence. """ import numpy as np import tensorflow as tf # Create the model model = tf.keras.Sequential([ tf.keras.layers.Embedding(input_dim=vocab_size, output_dim=embedding_dim), tf.keras.layers.Bidirectional(tf.kera [instruction] | Train a classification model to classify the sentiment of the given sentence. [input] | Sentence: I love this new book!

[output] | for i in range(0, n): print(i) [instruction] | Generate code for a for loop to iterate through the numbers from 0 to n-1. [input] | n = 5

[output] | my_dict.pop('d') [instruction] | Write code to delete the given key from the given dictionary. [input] | Dictionary: my_dict = {'a': 1, 'b': 2, 'c': 3, 'd': 4} Key: 'd'

[output] | One example algorithm for solving Sudoku is called 'Backtracking'. This algorithm works by first filling in possible solutions for the empty cells, then using a series of rules to determine the correct answer. The algorithm starts with each cell of the Sudoku and tries different numbers for it until [instruction] | What is an example of an algorithm for solving Sudoku? [input] |

[output] | A heuristic for the traveling salesman problem is to make use of the nearest neighbor algorithm or the brute-force algorithm. The nearest neighbor algorithm works by starting at a random node and visiting its nearest unvisited neighbor, then repeating the process until all nodes have been visited. T [instruction] | What is a heuristic for solving the traveling salesman problem? [input] |

[output] | def longest_no_repeat(s): max_length = 0 length = 0 seen = dict() for i in range(len(s)): if s[i] not in seen: length += 1 seen[s[i]] = i else: if length > max_length: max_length = length length = [instruction] | Design an algorithm to find the longest substring with no repeating characters in a given string. [input] | "abcabcbb"

[output] | def calculate_throughput(data_rate, packet_size): return data_rate / (packet_size / 8) # converting bits to bytes if __name__ == '__main__': data_rate = 10 # Mbps packet_size = 1000 # bits throughput = calculate_throughput(data_rate, packet_size) print(throughput) # 125000.0 [instruction] | Create a function to calculate the network's throughput given a data rate and a size of the packets. [input] | Data Rate = 10 Mbps; Packet size = 1000 bits

[output] | print("Hello World") [instruction] | Print “Hello World” using the print() function. [input] |

[output] | def count_substring(string1, string2): count = 0 for i in range(len(string2)-len(string1)+1): if string2[i:i+len(string1)] == string1: count += 1 return count [instruction] | Create a function that takes in two strings and returns the number of times the first string is found within the second string. [input] | string1 = "ab" string2 = "abcabcabc"

[output] | def sort(lst): for i in range(len(lst)): min_index = i for j in range(i+1, len(lst)): if lst[j] < lst[min_index]: min_index = j lst[i], lst[min_index] = lst[min_index], lst[i] return lst [instruction] | Create an algorithm to sort the given list of integers. [input] | [5, 7, 2, 4, 9]

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