← 목록

Synth · CodeAlpaca일부

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

[output] | def compute_sum(root): if not root: return 0 left_sum = compute_sum(root.left) right_sum = compute_sum(root.right) return root.val + left_sum + right_sum [instruction] | Compute the sum of numbers in a given tree. [input] | Tree Structure 5 / \ 3 7

[output] | public class HelloWorld { public static void main(String[] args) { for (int i = 0; i < 5; i++) { System.out.println("hello"); } } } [instruction] | Create a short Java program that prints out a word 5 times. [input] | Word: hello

[output] | #include<stdio.h> #include<string.h> int main() { char words[][10] = {"hello", "world", "apple", "zebra"}; int n = 4; int i, j; // sorting the phrases for (i = 0; i < n-1; i++) for (j = i+1; j < n; j++) if (strcmp(words[i], words[j]) > 0) [instruction] | Sort a list of words in alphabetical order using C. [input] | words = ["hello", "world", "apple", "zebra"]

[output] | CREATE TABLE users ( id INTEGER primary key, username VARCHAR(32) NOT NULL, password VARCHAR(256) NOT NULL ); [instruction] | Design a SQL table to store user information such as username and password. [input] |

[output] | class DecisionTree: def __init__(self,X,y): self.X = X self.y = y def fit(self, X,y): # Implement decision tree fitting algorithm def predict(self,X): # Implement decision tree prediction algorithm [instruction] | Implement a decision tree as a class in Python. [input] |

[output] | <html> <head> <title>Login Form</title> </head> <body> <form action="" method="POST"> <label>Username:</label><input type="text" /> <label>Password:</label><input type="password" /> <input type="submit" /> </form> </body> </ [instruction] | Create an HTML template for a login form having username and password. [input] |

[output] | for item in list_items: if 'a' in item: print(item) # Output apple banana carrot [instruction] | Iterate through a list and print only the elements that include the character 'a'. [input] | list_items = ["apple", "banana", "carrot", "durian"]

[output] | for i in range (1, 101): print(i) [instruction] | Use for loop to print all numbers from 1 to 100 in separate lines. [input] |

[output] | sum = 0 for n in range (1, 11): sum += n print(sum) [instruction] | Calculate the sum of the numbers from 1 to 10 and print out the result. [input] |

[output] | a, b = 0, 1 for i in range (12): print(a) a, b = b, a + b # Output 0 1 1 2 3 5 8 13 21 34 55 89 144 [instruction] | Generate a Fibonacci sequence up to the 12th term. [input] |

[output] | class Vector: def __init__(self, x, y): self.x = x self.y = y def length(self): return (self.x**2 + self.y**2)**0.5 [instruction] | Create a class named "Vector" with two attributes "x" and "y" and define a "length" method that returns the length of the vector. [input] |

[output] | def multiply(a, b): return a * b result = multiply(a, b) print(result) [instruction] | Create a function that multiplies two numbers and return the result. [input] | a = 10 b = 5

[output] | list = [1,2,3,4,5,6,7] sum = 0 for i in list: sum += i mean = sum/len(list) print(mean) [instruction] | Find the mean of the list of numbers [1,2,3,4,5,6,7] [input] |

[output] | list.sort() print(list) # Output [1,2,3,7,9] [instruction] | Sort the list of numbers [3,2,7,9,1] in ascending order. [input] | list = [3,2,7,9,1]

[output] | import random arr = [] for i in range(10): arr.append(random.randint(0, 9)) print(arr) [instruction] | Create an array of length 10 and fill each element randomly from 0 to 9. [input] |

[output] | length = len(arr) print(length) # Output 5 [instruction] | Find the number of elements in an array of integers [1,2,3,4,5]. [input] | arr = [1,2,3,4,5]

[output] | import re text = "I saw a cat in the park." result = re.sub(r'cat', 'dog', text) print(result) # Output I saw a dog in the park. [instruction] | Using regex, replace all occurrences of 'cat' with 'dog' in the following text. [input] | text = "I saw a cat in the park."

[output] | for i in range (1, 11): print(i**2) [instruction] | Create a loop that runs from 1 to 10 and prints the square of each number. [input] |

[output] | for i, item in enumerate(range(6)): print(i) [instruction] | How would you use the 'enumerate()' function in a for loop to print numbers from 0 to 5? [input] |

[output] | #!/bin/bash if [ $1%2 -eq 0 ] then echo "$1 is an even number" else echo "$1 is an odd number" fi [instruction] | Create a bash script to check if a given integer is even. [input] |

[output] | h1 { color: #4B0082; } [instruction] | Create a CSS stylesheet to turn all the h1 tags to a deep purple color. [input] |

[output] | class Addition: def add(self, x, y): return x + y [instruction] | Create a class "Addition" with a method called "add" which takes two integers as inputs and returns the sum of the two numbers? [input] |

[output] | def check_word(myString, word): if word in myString: return True return False [instruction] | Create a function that checks for a specific word in the string. [input] | myString = "This is a simple sentence."

[output] | The function is add_element(arr, element), which adds the given element to the given array and returns the modified array. [instruction] | Identify a function from the following code snippet which adds an element to the given array. [input] | arr = [1, 2, 3] def add_element(arr, element): return arr.append(element)

[output] | The total number of elements in the list is 5. [instruction] | Given a Python list, display the total number of elements in the list. [input] | mylist = [1, 2, 3, 4, 5]

[output] | def product_of_list(nums): product = 1 for num in nums: product *= num return product [instruction] | Write a function which takes a list of integers and returns an integer which is the product of all the integers in the list. [input] |

[output] | def longest_increasing_subsequence_length(nums): n = len(nums) LIS = [1] * n for i in range(1, n): for j in range(0, i): if nums[i] > nums[j] and LIS[i] < LIS[j] + 1: LIS[i] = LIS[j] + 1 return max(LIS) [instruction] | Design a function to get the length of the longest increasing subsequence in a given list of integers. [input] |

[output] | (1..8).each do |x| puts x end [instruction] | Create a Ruby program that takes a number input from the user and creates a loop that prints out each number from 1 to the input number. [input] | 8

[output] | function countMatchingChar(str1: string, str2: string): number { let count = 0; if(str1.length != str2.length) { return -1; // handle unequal lengths } for(let i = 0; i < str1.length; i++) { if(str1.charAt(i) === str2.charAt(i)) { count++; } } [instruction] | Create a function in TypeScript that takes two strings of equal length and returns the number of characters which match at the same position in the strings. [input] | "abcdefg", "hijklmn"

[output] | public class Main { public static void main(String[] args) { char ch = 'A'; int asciiCode = (int) ch; System.out.println("ASCII code of 'A' :" + asciiCode); } } [instruction] | Write a Java program to convert a character to an int. [input] | 'A'

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