← 목록

Synth · CodeAlpaca일부

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

[output] | int result; try { result = dividend / divisor; if (divisor == 0) throw new ArithmeticException("Divisor cannot be zero"); } catch (DivideByZeroException e) { Console.WriteLine("Exception caught: {0}", e); } [instruction] | Edit the following C# code to throw an exception if the divisor is equal to 0. [input] | int result = dividend / divisor;

[output] | class Student { constructor(name, age, email) { this.name = name; this.age = age; this.email = email; } } [instruction] | Create a JavaScript class named "Student" that has the following fields. [input] |

[output] | arr.reverse() # arr is now [6, 8, 2, 4] [instruction] | Reverse this array in-place using Python. [input] | arr = [4, 2, 8, 6]

[output] | The "==" operator is the equality comparison operator, which compares two values and returns true if they are equal. The "===" operator is the strict equality comparison operator, which compares two values and returns true only if both the values and their type are equal. [instruction] | Explain the difference between String comparison operators == and === in JavaScript. [input] |

[output] | nums = list(range(1, n+1)) # nums is now [1, 2, 3, 4, 5] [instruction] | Using the following code snippet, generate a list containing numbers from 1 to n. [input] | n = 5

[output] | result = '' for string in str_list: result += string # result is now "Iamalistofstrings" [instruction] | Convert this list of strings to a single string without using the "join" method. [input] | str_list = ["I", "am", "a", "list", "of", "strings"]

[output] | The code complexity of the given function is O(n), where n is the length of the list. [instruction] | Determine the code complexity for the following codse sample. [input] | def get_sum(list): sum = 0 for num in list: sum += num return sum

[output] | import re def get_num_words(inp_str): words = re.findall(r'\w+', inp_str) return len(words) if __name__ == '__main__': inp_str = 'This is a string of text' print(get_num_words(inp_str)) # Output: 4 words [instruction] | use regular expression to determine the number of words in a string. [input] | This is a string of text

[output] | """ Convert data into Excel format """ import csv def to_excel(data): with open('data.csv', 'w', newline='') as csvfile: fieldnames = ['name', 'age'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() for row in data: write [instruction] | Convert the following data into Excel Format. [input] | [ {'name': 'John', 'age': 20}, {'name': 'Paul', 'age': 22}, {'name': 'Ringo', 'age': 19} ]

[output] | """ Model the evolution of a population """ class Population: def __init__(self): self.population = [] self.generation = 0 def add_member(self, member): self.population.append(member) def next_generation(self): self.generation += 1 self.populati [instruction] | Design a data structure to model the evolution of a population. [input] |

[output] | def quick_sort(arr): if len(arr) < 2: return arr pivot = arr[0] less = [i for i in arr[1:] if i <= pivot] greater = [i for i in arr[1:] if i > pivot] return quick_sort(less) + [pivot] + quick_sort(greater) if __name__ == '__main__': arr = [7, 4, 5, 9, 1] prin [instruction] | Given a list of numbers, implement a quick sort algorithm. [input] | [7, 4, 5, 9, 1]

[output] | <!DOCTYPE html> <html> <head> <title>My Web Page</title> </head> <body> </body> </html> [instruction] | Set up a basic HTML page with a title that says "My Web Page". [input] |

[output] | SELECT * FROM Customers WHERE City = 'London'; [instruction] | Write a SQL query to select rows from the table "Customers" where the "City" column equals "London". [input] |

[output] | arr[2] = 5; [instruction] | Write a Java code snippet to set the 3rd element in an array of integers to the value 5. [input] | int[] arr = {1, 2, 3, 4, 5};

[output] | let sum = 3 + 5 + 7 + 17; [instruction] | Calculate the sum of 3, 5, 7 and 17 using JavaScript. [input] |

[output] | SELECT SUM(Amount) FROM Transactions; [instruction] | Write a SQL query that sums the values in the "Amount" column of a table called "Transactions". [input] |

[output] | string name; [instruction] | Create a C++ variable with the name "name" that can store a string value. [input] |

[output] | String alphaNumericString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789" + "abcdefghijklmnopqrstuvxyz"; StringBuilder sb = new StringBuilder(8); for (int i = 0; i < 8; i++) { int index = (int)(alphaNumericString.length() * Math.random()); sb.append [instruction] | Generate a unique 8 digit alphanumeric ID using Java. [input] |

[output] | <html> <head> <title>User Form</title> </head> <body> <form action="process_form.php" method="post"> Name: <input type="text" name="name"><br> Address: <input type="text" name="address"><br> <input type="submit" value="Submit"> </form> </body> </html> [instruction] | Generate an HTML form in PHP to gather user information such as name and address. [input] |

[output] | """ Program to read a list of words and print the most frequently used one Input: List of words Output: Most frequently used word """ def most_freq_word(words): # Create an empty dictionary freq = {} # Iterate over the list of words for word in words: # Check if wor [instruction] | Write a Python program that reads a list of words and prints the most frequently used one. [input] | ['apple', 'banana', 'orange', 'apple']

[output] | public class Contact { String name; int age; String phoneNumber; String email; String address; public Contact(String name, int age, String phoneNumber, String email, String address){ this.name = name; this.age = age; this.phoneNumber = ph [instruction] | Generate a class in Java for a contact record, including name, age, phone number, email, and address information. [input] |

[output] | int[] array = new int[5]; for(int i=0; i<array.length; i++){ array[i] = 0; } [instruction] | Edit the following code to return a length 5 array of zeros. [input] | int[] array = new int[10];

[output] | """ Function to reverse a given string Input: String Output: Reversed string """ def reverse_string(string): # Create an empty string to store the reversed string reversed_string = "" # Iterate over the string from the last character for i in range(len(string)-1, -1, -1): [instruction] | Output a string which is the reverse of the input string. [input] | "Hello World"

[output] | <h1>Introduction</h1> <h1>About</h1> [instruction] | Output a code to edit the following HTML to add a new heading 'Introduction' before the existing heading 'About'. [input] | <h1>About</h1>

[output] | SELECT * FROM customers WHERE account_balance > 1000; [instruction] | Write a SQL query to select all the customers who have an account balance of more than $1000. [input] |

[output] | def max_val(arr): maximum = arr[0] for i in arr: if i > maximum: maximum = i return maximum max_val([-1, 2, 4, 6, -3, 5]) # Output: 6 [instruction] | Write a function to output the maximum value possible from a given array. [input] | [-1, 2, 4, 6, -3, 5]

[output] | n = 5 total = 0 for i in range(n+1): total += i print(total) # Output: 15 [instruction] | Construct a for loop that calculates the sum of the numbers from 0 to n. [input] |

[output] | SELECT A.id, A.name, B.address FROM A INNER JOIN B ON A.id = B.id [instruction] | Generate an SQL query that will combine two tables. [input] | table A with 2 columns (id and name) and 2 rows (1, Tom) (2, Abigail) table B with 2 columns (id and address) and 2 rows (1, USA) (2, Canada)

[output] | import scikit-learn as sklearn # Load the data X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(X, y, test_size = 0.2, random_state = 0) # Train the classifier classifier = sklearn.naive_bayes.MultinomialNB() classifier.fit(X_train, y_train) # Test the classifier y_pred [instruction] | Create a text classifier using supervised learning. [input] |

[output] | import scikit-learn as sklearn # Load the data X = dataset[['email_body', 'send_from', 'subject', 'num_links']] y = dataset['is_spam'] X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0, stratify=y) # Train the model classifier = sklearn.linear_model.Logist [instruction] | Create a machine learning model that predicts whether an email is spam or not. [input] |

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