← 목록

Synth · CodeAlpaca일부

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

[output] | import threading import signal from time import sleep def exitThread(signum, frame): raise SystemExit def worker(): try: signal.signal(signal.SIGALRM, exitThread) signal.alarm(10) while True: print("Thread") sleep(1) threads = [ [instruction] | Modify the following code to kill a thread after 10 seconds. [input] | import threading from time import sleep def worker(): try: while True: print("Thread") sleep(1) threads = [] for x in range(40): t = threading.Thread(target=worker) threads.append(t) t.start()

[output] | [1, 7, 10, 11, 15] [instruction] | Create an array of 5 unique numbers between 1 and 15. [input] |

[output] | class Publisher: def __init__(self): self.observers = [] self.state = None def getState(self): return self.state def setState(self, state): self.state = state self.notifyAll() def add(self, observer): if observer not in [instruction] | Change the following code to implement the Observer Design Pattern in Python. [input] | class Publisher: def __init__(self): self.observers = [] def add(self, observer): if observer not in self.observers: self.observers.append(observer) else: print('Failed to add: {}'.format(observer)) def remove(self):

[output] | [1, 5, 6, 8, 13, 16, 18, 20, 21, 24, 25, 29, 31, 32, 36, 39, 40, 43, 44, 50] [instruction] | Create an array of 20 unique values from 1 to 50. [input] |

[output] | items = ['pen', 'paper', 'pencil'] [instruction] | Declare a variable named 'items' and assign it a list containing the elements ‘pen’, ‘paper’ and ‘pencil’ in Python. [input] |

[output] | fruits <- c("apple", "mango", "banana", "orange") [instruction] | Create a vector in R to store the elements ‘apple’, ‘mango’, ‘banana’ and ‘orange’. [input] |

[output] | string = "cbaefd" array = list(string) array.sort() print(array) [instruction] | Create an array from a given string and sort it in ascending order. [input] | string = "cbaefd"

[output] | import string import random def random_password(str_len): alphanumeric = string.ascii_letters + string.digits + string.punctuation return ''.join(random.choice(alphanumeric) for i in range(str_len)) random_password(16) [instruction] | Generate a random password of 16 characters that includes a mix of alphanumeric characters and punctuation. [input] |

[output] | def count_val(arr, x): count = 0 for i in arr: if i == x: count += 1 return count count_val(arr, x) [instruction] | Write a function that takes two arguments, an array arr and a value x, and returns the number of times x appears in the array arr. [input] | arr = [1, 2, 3, 4, 5, 6, 7, 8, 5] x = 5

[output] | string1 = "apple" string2 = "orange" length = min(len(string1), len(string2)) for i in range(length): if string1[i] != string2[i]: result = string1[i] < string2[i] break if result == True: print(string1 + " follows " + string2 + " alphabetically.") else: print(string2 + " follows " [instruction] | Write a code in Python for comparing two strings without using a built-in function. [input] | string1 = "apple" string2 = "orange"

[output] | import numpy as np arr = np.ones((3,3)) print(arr) [instruction] | Generate a two-dimensional array of 3 rows and 3 columns with all elements equal to 1. [input] |

[output] | list_copy = [x for x in given_list] [instruction] | How can we use a list comprehension to make a copy of a given list? [input] |

[output] | INSERT INTO users (name, age, gender) VALUES ('Adam', 34, 'Male'); [instruction] | Generate the SQL command to insert a new item in an existing table. [input] | Table Name: users Values: ('Adam', 34, 'Male')

[output] | matrix = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]] [instruction] | Convert a list of numbers to a 5x5 matrix. [input] | given_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]

[output] | function compareStrings(str1, str2) { if (str1.length !== str2.length) { return false; } for (let i === 0; i < str1.length; i++) { if (str1[i] !== str2[i]) { return false; } } return true; } [instruction] | Write a JavaScript function to compare two strings without using any built-in functions. [input] |

[output] | A simple approach to reverse an array is to use two index variables, one at the start and one at the end of the array. Swap the elements present at these two indexes and increment the first index and decrement the second index, until the indexes meet. Example: def reverseArray(arr, start, end): [instruction] | Describe a method to reverse the order of elements in a given array. [input] |

[output] | We can use the built-in min() function to find the minimum value in a list. This function takes an iterable such as a list, tuple or set as an argument and returns the smallest item in the iterable. For example, if given a list of numbers, the min() function would return the number with the lowest v [instruction] | Explain how to find the minimum value of a list. [input] |

[output] | <form> <input type="text" name="name" /> </form> [instruction] | Generate an HTML form with a text input box. [input] |

[output] | h1 { text-align: center; } [instruction] | Write a CSS rule to center-align the text of all <h1> elements on a web page. [input] |

[output] | SELECT * FROM Orders WHERE price > 1000; [instruction] | Write an SQL query to find all the records in a given table that have a price greater than $1000. [input] | Table name: Orders Fields: price (decimal), item_name (string)

[output] | Pattern detected: 87, 88, 89. Starting at index 0. [instruction] | Create a program which finds patterns in a stream of numbers and prints out the start of the pattern. [input] | 87, 88, 89, 87, 88, 89, 87, 88, 89

[output] | total_sum = 0 for num in range(15, 31): total_sum += num print(total_sum) [instruction] | Construct a for loop in Python to find the sum of all the the numbers between 15 and 30 (inclusive). [input] |

[output] | { "name": "John Doe", "age": 35, "occupation": "Software Engineer" } [instruction] | Construct a JSON Object of a person with their name, age, and occupation. [input] |

[output] | if user_input == 1: print('A') elif user_input == 2: print('B') elif user_input == 3: print('C') elif user_input == 4: print('D') else: print('F') [instruction] | Construct an if-else if condition to grade the user input (1 to 5) between A, B, C, D, or F. [input] |

[output] | def printOption(option): switch(option): case "M": print("Monthly") break case "Y": print("Yearly") break default: print("Invalid") [instruction] | Construct a switch-case statement to output "Monthly" if the user enters "M" to output "Yearly" if the user enters "Y", and "Invalid" if the user enters neither "M" nor "Y". [input] |

[output] | pattern = r'^(https?:\/\/)[\da-z\.-]+\.[a-z\.]{2,}\/?[\/\w \.-]*' [instruction] | Design a regex pattern to check if a given string is a valid URL or not. [input] |

[output] | class myClass(): def __init__(self): self.var1 = "Hello" self.var2 = "World!" self.var3 = 5 def method1(self): print(self.var1) def method2(self): print(self.var2) [instruction] | Construct a class in Python that contains three variables and two methods. [input] |

[output] | def sortString(string): words = string.split() words.sort() return (' '.join(words)) [instruction] | Write a function to sort a string containing several words alphabetically. [input] |

[output] | def get_order_info(order_time): query = "SELECT order_id, order_time, subtotal FROM orders WHERE order_time > %s" cursor.execute(query, (order_time, )) rows = cursor.fetchall() return rows [instruction] | Convert the following SQL statement into a Python def() and write the code. [input] | SELECT order_id, order_time, subtotal FROM orders WHERE order_time > NOW()

[output] | def sort_string(string): str_list = list(string) str_list.sort() return "".join(str_list) sorted_str = sort_string(string) [instruction] | Sort a string in alphabetical order. [input] | string = "edcba"

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