← 목록

Synth · CodeAlpaca일부

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

[output] | public static boolean isPointInsideRectangle(Point p, Rectangle r) { return (p.getX() <= r.getMaxX() && p.getX() >= r.getMinX() && p.getY() <= r.getMaxY() && p.getY() >= r.getMinY()); } [instruction] | Write a Java method to decide if one point is inside a given rectangle or not. [input] |

[output] | if name == "John": print("Welcome!") else: print("Goodbye!") [instruction] | Create an if-else statement that prints "Welcome!" if the input is "John" and "Goodbye!" if the input is "Caroline". [input] |

[output] | def find_common(list1, list2): common_elems = [] for elem in list1: if elem in list2: common_elems.append(elem) return common_elems [instruction] | Given two lists, create a function that finds the common elements between the two lists. [input] | list1 = [1, 2, 3, 4, 5] list2 = [2, 3, 4, 6, 7]

[output] | A global variable is a variable that is accessible and can be modified in any part of a program. It is not limited to the scope of any particular function. [instruction] | Define what a global variable is. [input] |

[output] | The "continue" statement is used to skip the current iteration of a loop and continue with the next iteration. It is commonly used to ignore certain items in a list or when the program should take a different action based on a particular condition. [instruction] | Explain what the "continue" statement does. [input] |

[output] | def get_email(): email = input("Please enter a valid email address: ") return email [instruction] | Write a function in Python to encourage user input by prompting the user "Please enter a valid email address." [input] |

[output] | let arrayToSort = [50, 34, 97, 56, 12, 99]; arrayTo Sort.sort((a, b) => b - a); console.log(arrayToSort); // [99, 97, 56, 50, 34, 12] [instruction] | Sort an array in descending order using JavaScript. [input] | [50, 34, 97, 56, 12, 99]

[output] | let totalSeconds = 15000; let days = Math.floor(totalSeconds / (24*60*60)); let remainingSeconds = totalSeconds % (24*60*60); let hours = Math.floor(remainingSeconds / (60*60)); let remainingSeconds2 = remainingSeconds % (60*60); let minutes = Math.floor(remainingSeconds2 / (60)); let seconds = rema [instruction] | Write a JavaScript program to convert a given number of seconds into the equivalent time in days, hours, minutes and seconds. [input] | 15000

[output] | let dividend = 9; let divisor = 5; let remainder = dividend % divisor; console.log(remainder); [instruction] | Write a JavaScript program to find the remainder when two given numbers are divided. [input] | 9 and 5

[output] | let scientists = ["Albert Einstein", "Isaac Newton", "Charles Darwin", "Marie Curie", "Galileo Galilei", "Stephen Hawking", "Sophie Germain", "Antoine Lavoisier", "Niels Bohr", "Blaise Pascal"]; [instruction] | Create an array to store 10 names of famous scientists. [input] |

[output] | #calculate the square root of a given number def get_square_root(num): root = num ** 0.5 return root if __name__ == '__main__': number = 16 root = get_square_root(number) print("Square root of {} is {}".format(number, root)) [instruction] | Create a code block that calculates the root of a given number [input] | Find the square root of 16

[output] | def cummulative_sum(arr): cum_sum = 0 for num in arr: cum_sum += num return cum_sum if __name__ == '__main__': test_list = [2, 4, 6, 8, 10] print('Cumulative Sum:', cummulative_sum(test_list)) [instruction] | Develop a code that can calculate the cumulative sum of an array [input] | [2, 4, 6, 8, 10]

[output] | #Add two parameters together and return the result def add_two_params(a, b): return a + b result = add_two_params(1, 2) print('The result is', result) [instruction] | Given a function that takes two parameters "a" and "b", write a code to add the two parameters together and return the result. [input] | a = 1, b = 2

[output] | #Function to find control characters def find_control_chars(string): control_chars = [ '\r', '\n' ] for char in control_chars: if char in string: return True return False string = 'This is a string\r\nwith some control characters' control_cha [instruction] | Write a code to find control characters such as carriage returns inside a given string [input] | 'This is a string\r\nwith some control characters'

[output] | #Calculate the applicable tax amount def get_tax_amount(income, country): #Country specific logic if country == 'Ireland': tax_rate = 0.20 else: tax_rate = 0.15 #Calulate tax amount tax_amount = income * tax_rate return tax_amount if __name__ == '__main__': [instruction] | Create a method to calculate the amount of tax to be paid based on the inputs of income and country. [input] | income = 20000, country = Ireland

[output] | #Return a random value from a given list import random def get_random_value(lst): n = random.randint(0, len(lst) - 1) return lst[n] test_list = [1, 4, 8, 12] random_value = get_random_value(test_list) print('Random value:', random_value) [instruction] | Write a code block to return a random value from a given list [input] | [1, 4, 8, 12]

[output] | # Bubble Sort algorithm def bubble_sort(lst): for i in range(len(lst)-1): for j in range(len(lst)-1-i): if lst[j] > lst[j+1]: lst[j], lst[j+1] = lst[j+1], lst[j] return lst # Insertion Sort algorithm def insertion_sort(lst): for i in range(1, len(lst) [instruction] | Generate three different sorting algorithms for a list of integers. [input] |

[output] | 83055109 16971134! [instruction] | Replace each letter in the following text with its corresponding number: [input] | Hello world!

[output] | def double_to_single(list) current_node = list.head while current_node current_node.next = current_node.other current_node.other = nil current_node = current_node.next end end [instruction] | Write a Ruby code to convert a double-linked list to a single-linked list. [input] |

[output] | // XPath query to retrieve all elements from the given XML string /root/child [instruction] | Given a valid XML string, write an XPath query to retrieve all the elements [input] | <?xml version="1.0"?> <root> <child name="child1" /> <child name="child2"> <subchild>subchild</subchild> </child> <child name="child3" /> </root>

[output] | UPDATE table_name SET Gender = 'Male' WHERE Name = 'John'; [instruction] | Write a SQL query to update the record of the column "Gender" to 'Male' where the column "Name" is 'John'. [input] |

[output] | question <- "Do you have a pet?" binary_input <- ifelse(question == "Do you have a pet?", 1, 0) print(binary_input) # prints 1 [instruction] | Create an R code to convert yes/no questions to binary input. [input] | Do you have a pet?

[output] | SELECT COUNT(DISTINCT myColumn) FROM myTable [instruction] | Write a SQL query to count the number of distinct values for a specific column in a table. [input] | Table Name: myTable Column Name: myColumn

[output] | import re pattern = re.compile(r'^\d{2}\/\d{2}\/\d{4}$') [instruction] | Create a regular expression to match dates in the MM/DD/YYYY format. [input] |

[output] | <form> Name: <input type="text" name="name"><br> Email: <input type="email" name="email"><br> <input type="submit" value="Submit"> </form> [instruction] | Create a HTML form with name, email address and a submit button. [input] |

[output] | SELECT e.name, a.file_name, a.file_url FROM employees e JOIN attachments a ON e.id = a.employee_id WHERE e.department = 'Sales' [instruction] | Create a SQL query to show all employee details with their attachments in a specific department. [input] | Department Name: Sales

[output] | class LED { private: int color; public: // default constructor LED() { color = 0; } // setter function void setColor(int c) { color = c; } // getter function int getColor() { return color; } }; [instruction] | Create a class in C++ for a light emitting diode (LED) object that describes the color of the LED. [input] |

[output] | def only_text(string) return string.gsub(/[0-9,]/, '') end only_text(string) // output: "This is a string with numbers such as and in it." [instruction] | Create a Ruby method to keep only text from a string. [input] | string = "This is a string with numbers such as 1, 2, and 3 in it."

[output] | def double_up(str): double_str = str + " " + str strlen = len(str) print(double_str[strlen - 1]) [instruction] | Read the following code and debug the errors. [input] | def double_up(str): double_str = str + " " + str strlen = len(str) print(double_str[strlen])

[output] | let employees = [{name: 'John', age: 30}, {name: 'Mary', age: 25}, {name: 'Kevin', age: 27}]; employees.sort((employee1, employee2) => { return employee2.age - employee1.age; }); [instruction] | Write a JavaScript code to sort an array of employee objects from oldest to youngest based on age property. [input] | [{name: 'John', age: 30}, {name: 'Mary', age: 25}, {name: 'Kevin', age: 27}]

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