← 목록

Synth · CodeAlpaca일부

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

[output] | try: # Make API call except Exception as e: # Handle error print("An error occurred:", e) [instruction] | Using the comment as a guide, edit the code to handle the error appropriately. [input] | try: # TODO: Make API call except Exception: # TODO: Handle error

[output] | factorial :: Integer -> String factorial n = show $ product [1..n] [instruction] | Create a function in Haskell that takes an integer and returns a string representing its factorial. [input] |

[output] | arr = [random.randint(0, 1) for _ in range(10)] [instruction] | Create an array of size 10 with each element being a random integer between 0 and 1. [input] |

[output] | def reverse_string(string): return string[::-1] [instruction] | Implement a function that returns the reversed version of a given string. [input] |

[output] | function sortString(str) { return str.split("").sort().join(""); } [instruction] | Write a JavaScript code to sort the characters of a string alphabetically. [input] |

[output] | public static int stringToInteger(String s) { int result = 0; int power = 0; for (int i = s.length() - 1; i >= 0; i--) { char ch = s.charAt(i); result += (ch - '0') * Math.pow(10, power); power++; } return result; } [instruction] | Create a Java method to interpret a given string into an integer. [input] |

[output] | const fs = require('fs'); // Logs the specified string function logString(str) { console.log(str); } logString('Log this string'); [instruction] | Create a Node.js script that logs a string. [input] |

[output] | public class TestConstructor { public TestConstructor() { } public TestConstructor(int n) { // code to run when constructor with parameter is called } } [instruction] | Create a Java class with an empty constructor and a parameterized constructor [input] |

[output] | <html> <body> <div> Content </div> <div> Content </div> </body> </html> [instruction] | Create an HTML page with two <div> elements [input] |

[output] | class CharCounter{ private: char charToCount; int counter; public: CharCounter(char c) : charToCount{c}, counter{0} {} void countChar(char c); int getCounter(); }; void CharCounter::countChar(char c){ if (c == this->charToCount) this->counter++; } int CharCounter::getCou [instruction] | Design a C++ class to count the occurrences of a character [input] |

[output] | // Create the array of integers int[] numbers = {10, 20, 25, 15}; // Iterate over array and print numbers divisible by 5 for (int number : numbers) { if (number % 5 == 0) { System.out.println(number); } } // Output: 10 20 25 [instruction] | Write a Java program that takes an array of integers and prints the numbers that are divisible by 5 [input] | [10, 20, 25, 15]

[output] | def sum_squares(k, n): sum = 0 for i in range(k, n+1): sum += i**2 return sum [instruction] | Modify the following code to compute the sum of squares of the numbers from k to n. [input] | def sum(k, n): sum = 0 for i in range(k, n+1): sum += i return sum

[output] | phrase, category This is a big mess, Disaster That was a nice evening, Joy I am feeling thirsty, Discomfort [instruction] | Categorize the following phrases into the given categories. [input] | phrase, category This is a big mess, Disaster That was a nice evening, Joy I am feeling thirsty, Discomfort

[output] | x = 10 y = 5 x = x + y print(x) # Prints 15 [instruction] | In the following code snippet, what will be the output of the print statement ? [input] | x = 10 y = 5 x = x + y print(x)

[output] | def largest_of_two(num1, num2): if num1 > num2: return num1 else: return num2 [instruction] | Design a function which takes two numbers as input and returns the largest one as output. [input] |

[output] | name = "John Smith" # str [instruction] | Assign the correct data type for the following variable. [input] | name = "John Smith"

[output] | def permutations(nums): if len(nums) == 1: return [nums] res = [] for i in range(len(nums)): for p in permutations(nums[:i] + nums[i+1:]): res.append([nums[i]] + p) return res if __name__ == '__main__': nums = [1, 2, 3] print(permutations(nums)) # [instruction] | Design a function which prints all the permutations of a given list of numbers. [input] |

[output] | def count_alphabets(string): count = 0 for i in range(len(string)): if string[i].isalpha(): count += 1 return count [instruction] | Create an algorithm that iterates through a given string and returns the number of alphabets present in the string. [input] | "abracadabra"

[output] | average_three <- function(x) { c(mean(c(x[2], x[1])), mean(x), mean(c(x[2], x[3]))) } [instruction] | Write a function in R that takes a vector as an argument and returns a new vector in which each element is the average of that element with its two neighbors from the original vector. [input] | c(1, 4, 2, 8, 6)

[output] | ^[6-9]\d{9}$ [instruction] | Create a regular expression pattern in JavaScript that checks if a given string is a valid mobile phone number in India. [input] |

[output] | # Load the dataset X, y = <contents of the dataset> # Split the dataset X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0) # Train the model model = LogisticRegression() model.fit(X_train, y_train) # Evaluate the model y_pred = model.predict(X_test) accuracy [instruction] | Create a machine learning model in Python using the given data that classifies the data into either 'positive' or 'negative'. [input] | <contents of the dataset>, data type: binary classification

[output] | import java.util.*; public class StackImplementation { private Stack<Integer> stack; public StackImplementation() { stack = new Stack<>(); } public void push(int x) { stack.push(x); } public int pop() { if (stack.isEmpty()) { Syst [instruction] | Implement a data structure in Java that implements a stack with the following methods: 'push', 'pop', 'peek', and 'isEmpty'. [input] |

[output] | <?xml version="1.0"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <table border="1"> <tr> <th>Book</th> <th>Author</th> </tr> <xsl:for-each select="catalog/book"> <tr> [instruction] | Parse the given XML document using an XSLT transformation and create an HTML table with the list of books and their authors. [input] | <the content of the xml document>

[output] | <!DOCTYPE html> <html> <head> <style> h1{ font-size: 1.5em; } @media only screen and (min-width: 600px) { h1 { font-size: 2em; } } @media only screen and (min-width: 900px) { h1 { font-size: 2.5em; } } </style> </head> <body> <h1>My Ti [instruction] | Create a web page using HTML and CSS where the font size of the content increases with the screen size. [input] |

[output] | strings = ["Hello", "World", "Foo", "Bar", "Baz"] count = 0 strings.each do |str| if str.length > 5 count += 1 end end puts "The number of strings longer than 5 characters is: #{count}" [instruction] | Create a Ruby program that takes a group of strings and returns the number of strings longer than 5 characters. [input] | ["Hello", "World", "Foo", "Bar", "Baz"]

[output] | def findMin(arr): current_min = arr[0] for num in arr: if num < current_min: current_min = num return current_min [instruction] | Find the minimum value from a given array. [input] | [3, -2, 4, 7]

[output] | A linked list is a linear data structure that consists of a sequence of elements, each element containing a pointer to the next element in the list. Some implementations may also contain a pointer to the previous element in the list. Pseudo-code would look like: START Class Node int data N [instruction] | Describe how a linked list data structure works in pseudo code. [input] |

[output] | sentence = "I love coding in Python" letter = "P" words_starting_with_P = [word for word in sentence.split() if word.startswith(letter)] print(words_starting_with_P) # Output: ['Python'] [instruction] | Develop a Python code to extract all words from a sentence that begin with a specific letter. [input] | sentence = "I love coding in Python" letter = "P"

[output] | import requests from bs4 import BeautifulSoup url = 'https://www.imdb.com/search/title/?title_type=feature&sort=num_votes,desc&view=simple&count=250&start=1' html_doc = requests.get(url).text soup = BeautifulSoup(html_doc, 'html.parser') # extract data from HTML table table = soup.find('table', a [instruction] | Write a web scraper in Python to collect the data from the top 1000 IMDB movies [input] |

[output] | arr1 = [1, 2, 3] arr2 = [4, 5, 6] # Initialize new array arr_sum = [0 for _ in range(len(arr1))] # Add the values of both arrays for i in range(len(arr1)): arr_sum[i] = arr1[i] + arr2[i] print(arr_sum) # Output: [5, 7, 9] [instruction] | Create a new array of integers which contains the sum of corresponding elements of two existing arrays. [input] | arr1 = [1, 2, 3] arr2 = [4, 5, 6]

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