← 목록

Synth · CodeAlpaca일부

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

[output] | function removeChar(str, char){ return str.replace(new RegExp(char, 'g'), ''); } [instruction] | Write a JavaScript program to remove all the occurrences of a specified character from a string. [input] | The quick brown fox

[output] | let arr = []; for (let i = 0; i < 5; i++) { arr.push(Math.floor(Math.random() * 10 + 1)); } console.log(arr); [instruction] | Create an array of 5 random numbers between 1 and 10 and output it to the console. [input] |

[output] | def multiply(x,y) { return x*y x = 5 y = 4 print(multiply(x,y)) [instruction] | Debug and fix the code in the given input. [input] | def multiply(x,y) { return x*y x = 5 y = 4 print multiply(x,y)

[output] | public static String reverseString(String s) { StringBuilder sb = new StringBuilder(); for (int i = s.length() - 1; i >= 0; i--) { sb.append(s.charAt(i)); } return sb.toString(); } [instruction] | Create a Java program that takes in a String and returns a String with the letters of the original String reversed. [input] | string = "Hello"

[output] | class Car: def __init__(self, make, model, year): self.make = make self.model = model self.year = year self.mileage = 0 def getMileage(self): return self.mileage [instruction] | You need to add a feature to the existing code in the given input. [input] | class Car: def __init__(self, make, model, year): self.make = make self.model = model self.year = year

[output] | def fibonacci(n): if n<0: print("Incorrect input") # First Fibonacci number is 0 elif n==0: return 0 # Second Fibonacci number is 1 elif n==1: return 1 else: a = 0 b = 1 for i in range(2,n+1): c = a + b [instruction] | Re-write the code in the given input to make it more efficient. [input] | def fibonacci(n): if n <= 1: return n else: return(fibonacci(n-1) + fibonacci(n-2))

[output] | <!DOCTYPE html> <html> <head> <title>String Case Transformer</title> </head> <body> <input type="text" id="inputStr"> <button onclick="transformCase('upper')">Upper Case</button> <button onclick="transformCase('lower')">Lower Case</button> <script> function transformC [instruction] | Create an HTML page with an input field and a button. The input field should take a sentence and the two button should "Upper Case" and "Lower Case" respectively. When clicked, it should upper case or lower case the sentence in the input field. [input] |

[output] | SELECT * FROM authors WHERE age > 18 [instruction] | Write a SQL statement to select all the authors whose age is greater than 18. [input] |

[output] | public void btnClick_Click(object sender, System.EventArgs e) { System.Console.WriteLine("Button clicked!"); } [instruction] | Create a C# event handler that is triggered when a button is clicked, and prints the text "Button clicked!" [input] |

[output] | def unique_str(s1, s2): res = "" for i in s1: if i not in s2: res += i return res [instruction] | Given two strings s1 and s2, write a function to return a new string containing the characters present only in s1. [input] | s1 = "abcdef" s2 = "fghijk"

[output] | SELECT first_name, last_name FROM employees WHERE location = "New York"; [instruction] | Write a SQL query to select the first and last name of all employees that are located in New York. [input] |

[output] | def evaluate(expression): expr = expression.replace(" ","") expr_list = expr.split("+") result = float(expr_list[0]) + float(expr_list[1]) return result [instruction] | Design a function to evaluate an expression represented as a string. [input] | expression = "2.0+2.1"

[output] | SELECT id, name, date FROM Events ORDER BY date DESC; [instruction] | Using SQL, select the columns from the table below and order them in descending order by the "date" column. [input] | Table Name: Events Columns: id, name, date

[output] | import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'Angular Application'; } [instruction] | Generate a working Angular program [input] |

[output] | public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView textView = findViewById(R.id.text_view); // You can use [instruction] | Generate a working Android program to display a simple string [input] |

[output] | #include <iostream> #include <unordered_map> using namespace std; int numOfDuplicates(int arr[], int n) { unordered_map<int, int> freq; for (int i = 0; i < n; i++) { freq[arr[i]]++; } int count = 0; for (auto i : freq) { if (i.second > 1) [instruction] | Program a function in C++ which finds the number of duplicate elements in an array. [input] | array: [1, 3, 2, 5, 2, 3]

[output] | def calculate_levenshtein_distance(str1, str2): distances = np.zeros((len(str1)+1, len(str2)+1)) for i in range(0, len(str1)+1): distances[i, 0] = i for j in range(0, len(str2)+1): distances[0, j] = j for i in range(1, len(str1)+1): for j in range(1, len(s [instruction] | Implement a function in Python that calculates the Levenshtein Distance of two strings. [input] | str1 = "hackathon" str2 = "hack"

[output] | def sum_of_square_range(a, b): sum = 0 for i in range(a, b+1): sum += i * i return sum [instruction] | Create a function in Python that takes two parameters and returns the sum of squares of all numbers between them [input] |

[output] | def all_even(lst): for num in lst: if num % 2 != 0: return False return True [instruction] | Given a list of numbers, design a function in Python to check if all numbers in the list are even [input] |

[output] | my_dict = { "one": 1, "two": 2, "three": 3 } [instruction] | Create a dictionary in Python whose keys are strings and values are integers [input] |

[output] | def first_n_elements(array, n): return array[:n] [instruction] | Create a program in Python to return the first n elements from an array [input] |

[output] | for n in range(2, 101): for i in range(2, n): if n % i == 0: break else: print(n, end = ' ') [instruction] | Print out the prime numbers between 0 to 100. [input] |

[output] | def max_subarray_sum(arr): max_sum = 0 current_sum = 0 for i in range(len(arr)): current_sum += arr[i] if current_sum > max_sum: max_sum = current_sum if current_sum < 0: current_sum = 0 return max_sum [instruction] | Create an algorithm that finds the maximum subarray sum in a given array. [input] | [-2, 1, -3, 4, -1, 2, 1, -5, 4]

[output] | def get_vowels(str): vowels = ['a', 'e', 'i', 'o', 'u'] res = [] for letter in str: if letter.lower() in vowels: res.append(letter) return res [instruction] | Edit the following code to generate a list of the vowels in a given string. [input] |

[output] | def classify_array_length(arr): if len(arr) % 2 == 0: return 'even' else: return 'odd' [instruction] | Create a function to classify an array as odd or even length. [input] |

[output] | def reverse_words(string): return " ".join(string.split(" ")[::-1]) [instruction] | How would you reverse the words order in a given string? [input] |

[output] | def next_mult_of_7(num): return num + (7 - num%7) [instruction] | Write a function that takes a positive integer and returns the next number which is divisible by 7. [input] |

[output] | def count_greater_than_ten(nums): return len([n for n in nums if n > 10]) [instruction] | Given a list of numbers, write a Python function to count how many numbers in the list are greater than 10. [input] |

[output] | def print_dict_key_value(dic): for key, value in dic.items(): print(f"{key}: {value}") [instruction] | Given a dictionary, write a Python function to print all the key-value pairs in the dictionary. [input] |

[output] | def construct_palindrome(string, N): length = len(string) mid = length // 2 left = string[:mid] right = left[::-1] if length % 2 == 0: left = string[:mid - (N - 1)] right = left[::-1] else: left = string[:mid - N] right = string[mid + 1:(mid [instruction] | Given a string and an integer N, write a Python function to construct the Nth palindromic string. [input] |

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