← 목록

Synth · CodeAlpaca일부

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

[output] | if key in dictionary: # execute this block of code else: # execute this block of code [instruction] | How to check for a key in a dictionary in Python? [input] |

[output] | $substr = substr $string, 0, 2; [instruction] | How can we extract the first 2 characters from a string in Perl? [input] |

[output] | def find_max_index(arr): if len(arr) == 0: return None max_val = arr[0] max_index = 0 for i in range(1, len(arr)): if arr[i] > max_val: max_val = arr[i] max_index = i return max_index arr = [2, 5, 9, 4, 10] max_index = find_max_index(arr) [instruction] | Write a function in Python that accepts an array as an argument and returns the index of the item with the maximum value. [input] | arr = [2, 5, 9, 4, 10]

[output] | SELECT c.first_name, c.last_name, SUM(o.total) AS total_spent FROM Customer c JOIN Order o ON c.id = o.customer_id GROUP BY c.first_name, c.last_name [instruction] | Write an SQL query to display the customer's first name, last name, and total spent. [input] | Customer table: id | first_name | last_name | points 1 | Harry | Potter | 500 Order table: order_id | customer_id | total 23 | 1 | 25

[output] | def random_arr(arr): idx = random.randint(0, len(arr)-1) return (arr[idx], idx) [instruction] | Rewrite the following function so that it returns a tuple instead of two separate values. [input] | def random_arr(arr): idx = random.randint(0,len(arr)-1) return arr[idx], idx

[output] | def subtract(num1, num2): return num1 - num2 result = subtract(3, 2) print(result) # Output: 1 [instruction] | Create a function that takes two integer arguments, subtracts the second one from the first one, and returns the result. [input] | num1 = 3, num2 = 2

[output] | class BankAccount: def __init__(self, name, balance, interest_rate): self.name = name self.balance = balance self.interest_rate = interest_rate def deposit(self, amount): self.balance += amount def withdraw(self, amount): self.balance -= amount [instruction] | Design a class BankAccount that represents a bank account with the attributes name, balance, and interest_rate. [input] |

[output] | def sum_set(my_set): total = 0 # Initialize total for num in my_set: total += num return total my_set = {2, 3, 4, 5} total = sum_set(my_set) print(total) # Output 14 [instruction] | Write an algorithm that takes a set of numbers and returns the sum of all numbers in the set. [input] | my_set = {2, 3, 4, 5}

[output] | SELECT * FROM Orders ORDER BY order_id DESC LIMIT 3 [instruction] | Write a query to select the last three records from the table "Orders". [input] | Order table: order_id | customer_id | total 21 | 2 | 10 22 | 4 | 15 23 | 1 | 25 24 | 3 | 20

[output] | def sum_of_two_numbers(x, y): if type(x) is not int or type(y) is not int: return None return x + y [instruction] | Create a function to calculate the sum of 2 numbers and return 'None' if both the parameters are not numbers. [input] |

[output] | for i in range(len(arr)): print("Index: " + str(i) + ", Value: " + str(arr[i])) [instruction] | Using a single 'for' loop, iterate through an array and print out the indices and values of each element to the console. [input] | [2, 5, 8, 9, 10]

[output] | import unittest class TestArithmeticFunction(unittest.TestCase): def test_sum(self): self.assertEqual(arithmetic_function(2, 5), 7) self.assertEqual(arithmetic_function(-4, 9), 5) self.assertEqual(arithmetic_function(-2, 0), -2) if __name__ == '__main__': unittest.m [instruction] | Write a test suite to test an arithmetic function that takes two arguments and returns the sum. [input] |

[output] | def count_unique_characters(str): characters = set() for char in str: characters.add(char) return len(characters) [instruction] | Create a method that takes a string as a parameter and returns the number of unique characters present in the string. [input] | python

[output] | \d{4}-\d{2}-\d{2} [instruction] | Create a regex pattern to match the following string: "2019-08-21". [input] |

[output] | def sort_by_length(arr): arr.sort(key=len) return arr [instruction] | Update the given code to sort an array of strings based on their lengths. [input] | arr = ["dogs", "cat", "lion"]

[output] | import random def random_in_range(): return random.randint(0, 1000) [instruction] | Create a function to generate a random number within the range of 0 and 1000. [input] |

[output] | message = "Hello World!" value = 1 [instruction] | Change the variable names in the given code to comply with the chosen coding standard. [input] | x = "Hello World!" y = 1

[output] | import random def random_string(arr): return ''.join(random.sample(arr, 8)) [instruction] | Using the input provided, generate a random string consisting of 8 characters. [input] | [a, b, c, d, e, f, g, h]

[output] | <div> <span class="tag" style="font-size: 300%;">The</span> <span class="tag" style="font-size: 200%;">quick</span> <span class="tag" style="font-size: 250%;">brown</span> <span class="tag" style="font-size: 150%;">fox</span> <span class="tag" style="font-size: 200%;">jumps</span> <span [instruction] | Create a tag cloud to visualize the most frequent words in the following sentence. [input] | The quick brown fox jumps over the lazy dog

[output] | The variable in the above program is 'number'. [instruction] | Identify all the variables in this C++ program. [input] | #include <iostream> int main() { int number = 10; std::cout << number; return 0; }

[output] | func factorial(_ n: UInt) -> UInt { if n == 0 { return 1 } return n * factorial(n - 1) } print(factorial(7)) [instruction] | Write a Swift program to calculate the factorial of a given integer. [input] |

[output] | const compareIgnoreCase = (string1, string2) => { return string1.toUpperCase() === string2.toUpperCase(); }; compareIgnoreCase("Hello", "heLLo"); // true [instruction] | Write a JavaScript program to compare two Strings for equality, ignoring case. [input] | String1: 'Hello' String2: 'heLLo'

[output] | gcc -c yourprogram.c gcc -o yourprogram yourprogram.o -L/path/to/shared/library -lfoo [instruction] | Compile a given C program and link it with a shared library. [input] | // program code given #include <stdio.h> int main() { printf("Hello World"); return 0; } //Shared Library libfoo.so

[output] | {"people": [ { "name": "John", "age": 24 }, { "name": "Max", "age": 27 } ]} [instruction] | Construct a JSON object from an array of objects. [input] | // Given Array [ { "name": "John", "age": 24 }, { "name": "Max", "age": 27 } ]

[output] | HashMap<String, String> map = new HashMap<>(); map.put("name", "John"); [instruction] | Write a Java code to create a HashMap and add elements into it. [input] | //Given Key and Value // key: "name" // value: "John"

[output] | total = 0 for i in arr: total += i average = total / len(arr) print(average) # 5.6 [instruction] | What is the average value of all elements in a given array? [input] | //Given Array [1, 8, 4, 5, 9]

[output] | function daysLeft(date){ let today = new Date(); let endDate = new Date(date); let timeDifference = endDate - today; let daysLeft = Math.ceil(timeDifference / (1000 * 60 * 60 * 24)); return daysLeft; } [instruction] | Write a JavaScript function to find the number of days left from today to a given date. [input] | let date = "12/20/2020";

[output] | SELECT * FROM Employees ORDER BY Salary ASC LIMIT 1 [instruction] | Create a MySQL query to return the employee details from the "employees" table with the minimum salary. [input] | Table Name: Employees Columns: Emp_ID, First_Name, Last_Name, Job_Position, Salary

[output] | CREATE TABLE customers ( CustomerID int NOT NULL AUTO_INCREMENT, Name varchar(255) NOT NULL, Address varchar(255) NOT NULL, Phone varchar(255) NOT NULL, PRIMARY KEY (CustomerID) ); [instruction] | Create a MySQL table named "customers" with 4 columns: "CustomerID", "Name", "Address" and "Phone". [input] |

[output] | function commonKeys(array1, array2) { let commonKeys = []; for (let i = 0; i < array1.length; i++) { if (array2.indexOf(array1[i]) !== -1) { commonKeys.push(array1[i]); } } return commonKeys.length; } [instruction] | Design a function to find the number of common keys between two arrays. [input] | let array1 = ["a", "b", "c", "d", "e", "f"]; let array2 = ["b", "d", "f", "g", "h", "i"];

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