← 목록

Synth · CodeAlpaca일부

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

[output] | def sortInts(nums): # Traverse through all array elements for i in range(len(nums)): # Last i elements are already in place for j in range(0, len(nums)-i-1): # traverse the array from 0 to n-i-1 # Swap if the element found is greater [instruction] | Suggest an algorithm in Python for sorting an array of integers from smallest to largest. [input] | nums = [3, 7, 5, 6, 1]

[output] | # Load the libraries library(caret) library(Metrics) # Create the training and testing sets split = createDataPartition(iris$Species, p = 0.75, list = FALSE) train_set = iris[split, ] test_set = iris[-split, ] # Train the model model = train(Species ~ ., data = train_set, method = "rpart") # Make [instruction] | Implement a simple machine learning algorithm in R to classify a given dataset. [input] |

[output] | # Load the libraries from sklearn.svm import SVC from sklearn.model_selection import train_test_split # Split the data X = data.iloc[:, :-1] y = data.iloc[:, -1] X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, random_state=42) # Train the model svm_model = SVC(gamma='auto') s [instruction] | Build a classifier in Python using the Scikit-learn library. [input] |

[output] | nums.sort() top_3 = nums[-3:] # reverse to great in descending order top_3.reverse() print(top_3) # Output [10, 9, 8] [instruction] | Output the top 3 values of the given array in descending order. [input] | nums = [4, 8, 2, 10, 9, 6, 1]

[output] | // Returns true if key is present in given BST boolean search(Node root, int key) { // Base Case if (root == null) return false; // If key is present at root if (root.key == key) return true; // Recursive calls for non-empty subtrees boolean le [instruction] | Suggest an algorithm for checking if a given key exists in a binary search tree in Java. [input] |

[output] | <html> <head> <title>My page</title> </head> <body> </body> </html> [instruction] | Create a HTML page with a header containing the text "My page" and an empty body section. [input] |

[output] | public class Welcome { public Welcome() { System.out.println("Welcome to my program"); } } [instruction] | Create a Java class that prints "Welcome to my program" when initialized. [input] |

[output] | import json import requests url = 'https://en.wikipedia.org/w/api.php?action=query&format=json&prop=revisions&titles=India' response = requests.get(url) data = json.loads(response.text) population = data['query']['pages']['571045']['revisions'][0]['*'].split('\n')[3].split('=')[1].strip().split('|' [instruction] | Using data from the Wikipedia API, write a Python program to list the population of India. [input] |

[output] | javac MyClass.java [instruction] | Compile the following Java program using javac in command line. [input] | public class MyClass { public static void main(String[] args) { System.out.println("Hello World"); } }

[output] | <form action="receive_email.php" method="post"> <input type="email" name="email" required> <input type="submit" value="Submit"> </form> [instruction] | Write a HTML form that submits a user-entered email address to a php script. [input] |

[output] | $(document).ready(function(){ alert("Popup box!"); }); [instruction] | Write a jQuery script to display a popup box when a web page is loaded. [input] |

[output] | def greet(name): return "Hello " + name + "!" [instruction] | Create a function that takes in a name and returns a string that greets the person by name. [input] | John

[output] | #include <iostream> #include <vector> struct Item { int cost; std::string description; }; // Define optimization problem int minimizeCost(int max_cost, std::vector<Item> budget_items) { // Initialize min_cost int min_cost = 0; // Choose items that add up to max_cost or less [instruction] | Write an optimization problem in C++ to minimize the cost of a budget planning problem. [input] | max_cost = 500, budget_items = [{cost: 100, description: PrintBook}, {cost: 250, description: EditBook}]

[output] | SELECT * FROM employees WHERE last_name = "Smith"; [instruction] | Write a query in SQL to select all employees with last name "Smith". [input] |

[output] | # prompt user for input num = input("Enter a number : ") # convert to an int num = int(num) # compute the square square = num**2 # print the output print("The square of",num,"is",square) [instruction] | Write a script to output the square of a number entered by the user. [input] |

[output] | [a-z]{5,} [instruction] | Write a regular expression to match a word, which has at least five letters and that only consists of lowercase alphabets. [input] |

[output] | def sortArray(arr): arr.sort(reverse = True) return arr [instruction] | Sort an array of integers from largest to smallest. [input] |

[output] | def searchString(para, string): for word in para.split(): if word == string: return True return False [instruction] | Write a function to search for an input string in a given paragraph. [input] | Paragraph:The quick brown fox jumps over the lazy dog String: brown

[output] | class Car: def __init__(self, speed, colour): self.speed = speed self.colour = colour [instruction] | Create a class for a car object with properties such as speed and colour. [input] |

[output] | The maximum size of a virtual memory address used by a 32-bit Intel 8086 processor is 4 gigabytes (2^32 bytes). [instruction] | What is the maximum size of a virtual memory address used by 32-bit Intel 8086 processor? [input] |

[output] | def isAnagram(s1, s2): # Get lengths of both strings n1 = len(s1) n2 = len(s2) # If lengths of both strings are not same, then they are not anagram if n1 != n2: return False # Sort both strings s1 = sorted(s1) s2 = sorted(s2) # Compare [instruction] | Compare two strings and output true if they are an anagram. [input] | s1 = "listen" s2 = "silent"

[output] | def insertAtBegining(arr,element): arr.insert(0, element) return arr # Driver code arr = [1, 2, 3, 4] element = 0 print(insertAtBegining(arr, element)) [instruction] | Write a code to insert an element at the beginning of an array. [input] | arr = [1, 2, 3, 4] element = 0

[output] | def replaceSubstring(string, substring1, substring2): string = string.replace(substring1, substring2) return string # Driver code string = "I am coding in python" substring1 = "coding" substring2 = "hacking" print("String after replacement is:", replaceSubstring(string, substring1, su [instruction] | Write a code to replace a substring inside a string with another substring. [input] | string = "I am coding in python" substring1 = "coding" substring2 = "hacking"

[output] | def removeIndex(arr, index): if index < 0 or index >= len(arr): return arr arr.pop(index) return arr # driver code arr = [4, 10, 15, 23, 0] index = 3 print("Array after removing element at index 3 is:", removeIndex(arr, index)) [instruction] | Remove the element at a given index from an array. [input] | arr = [4, 10, 15, 23, 0] index = 3

[output] | When a return statement is encountered in a function, it denotes the end of function execution and the function immediately returns control to the calling program. The value returned by the function can be accessed by the calling program. [instruction] | What happens when a return statement is encountered in a function? [input] |

[output] | Function call is an invocation of a function where as a function definition is the code block of the function denoted by its signature, parameters and the code body. Function call happens when the function is invoked with appropriate arguments, while function definition happens when the function is [instruction] | Describe the difference between function call and function definition. [input] |

[output] | def factorial(num): final_factorial = 1 for i in range(1, num + 1): final_factorial *= i return final_factorial [instruction] | Create an algorithm for finding the factorial of a number using a for loop. [input] |

[output] | public static boolean isArmstrongNumber(int number) { int originalNumber, remainder, result = 0; originalNumber = number; while (originalNumber != 0) { remainder = originalNumber % 10; result += Math.pow(remainder, 3); originalNumber /= 10; } if( [instruction] | Generate an appropriate function in Java to check if a given number is an Armstrong number. [input] |

[output] | public static int getSmallestElementRecursive(int[] arr, int start, int end) { if (start == end) { return arr[start]; } int min = getSmallestElementRecursive(arr, start+1, end); if (arr[start] < min) { return arr[start]; } else { return min; } } [instruction] | Develop an algorithm to find the smallest element in a given array of integers using recursion. [input] |

[output] | def print_prime_numbers(start, end): for i in range(start, end + 1): if is_prime_number(i): print(i, end = " ") def is_prime_number(num): if num > 1: # Iterate from 2 to n / 2 for i in range(2, num//2): if ( [instruction] | Generate a function in Python to print all prime numbers in a given range. [input] |

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