← 목록

Synth · CodeAlpaca일부

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

[output] | # Node class to define a node of a BST class Node(object): # Constructor def __init__(self, data): self.data = data self.left = None self.right = None # Function to delete a given node from BST def delete_node(root, key): # base case if root i [instruction] | Write a code to delete a node from a given BST. [input] |

[output] | let prices = []; let pricesRegex = /£\d+(?:\.\d+)?/g; let matches = str.match(pricesRegex); for (let i= 0; i < matches.length; i++) { prices.push(matches[i]); } console.log(prices); // ["£1.45","£2.50","£2.00"] [instruction] | Using a regular expression, extract all prices of items from a given HTML string. [input] | <div> Price of tea is £1.45, price of burger is £2.50, price of coffee is £2.00. </div>

[output] | let list = ["item1", "item2", "item3", "item4"]; for (let i = 0; i < list.length; i++) { console.log(i, list[i]); } // Output: // 0 item1 // 1 item2 // 2 item3 // 3 item4 [instruction] | How would you use a for loop to print the index and item of a list? [input] |

[output] | def print_asterisks(n): for i in range(n): print("*", end="") print("") [instruction] | Write a Python function to print a string of given length n filled with asterisks. [input] |

[output] | def test_even_odd(num): if num % 2 == 0: print("The number is even") else: print("The number is odd") [instruction] | How would you use an if-else statement to test whether a number is even or odd? [input] |

[output] | class Product: def __init__(self, name, description, price): self.name = name self.description = description self.price = price def __str__(self): return f"Name: {self.name}\nDescription: {self.description}\nPrice: {self.price}" [instruction] | Create a Python class for a product that includes data fields for name, description, and price. [input] |

[output] | try: input_num = int(input("Enter a number: ")) except ValueError: print("Please enter a valid number") [instruction] | Using a try-except statement, write a Python code to handle a ValueError which arises if the input is not a number. [input] |

[output] | let n = 10; let sum = 0; let i = 0; while (i <= n) { sum += i; i++; } console.log(sum); // prints 55 [instruction] | How would you use a while loop to sum up numbers from 0 to n? [input] |

[output] | for key,value in mydict.items(): print("Key: " + key + "; Value: " + str(value)) # Output: # Key: name; Value: John # Key: age; Value: 30 # Key: city; Value: New York [instruction] | Using a for-in loop, print out the keys and values of a given dictionary. [input] | mydict = { "name": "John", "age": 30, "city": "New York" }

[output] | switch (n) { case 1: console.log("Monday"); break; case 2: console.log("Tuesday"); break; case 3: console.log("Wednesday"); break; case 4: console.log("Thursday"); break; case 5: console.log("Friday"); break; case 6: console.log("Saturday"); [instruction] | How would you use a switch statement to print the corresponding day to a number? [input] |

[output] | def split_list(list): start = 0 end = len(list) - 1 left_sum = 0 right_sum = sum(list[start:end+1]) while start < end: right_sum -= list[end] if left_sum == right_sum: break left_sum += list[start] start += 1 if left_sum == right [instruction] | Write a code to split a list of numbers into two sets with equal sum [input] | [1, 2, 3, 4, 5, 6, 7]

[output] | def deg_to_rad(deg): return (deg * 3.14)/180 if __name__ == '__main__': deg = 90 rad = deg_to_rad(deg) print(rad) # prints 1.571 [instruction] | Convert a given number from degrees to radians. [input] | 90

[output] | def search_substring(string, substr): if substr in string: return True else: return False if __name__ == '__main__': string = "Hello World" substr = "llo" result = search_substring(string, substr) print(result) # prints True [instruction] | Write code for a substring search [input] | String: "Hello World" Substring: "llo"

[output] | def find_max_subseq(str1, str2): n1 = len(str1) n2 = len(str2) dp = [[0 for _ in range(n2 + 1)] for _ in range(n1 + 1)] for i in range(1, n1 + 1): for j in range(1, n2 + 1): if(str1[i - 1] == str2[j - 1]): dp[i][j] = dp[i - 1][j - 1] + 1 [instruction] | Create a program to find the maximum length common subsequence of two given strings. [input] | String1: "abcdgf" String2: "abcdhfe"

[output] | def fibonacci_seq(n): seq = [0, 1] for i in range(2, n): seq.append(seq[i-1] + seq[i-2]) return seq if __name__ == '__main__': n = 10 result = fibonacci_seq(n) print(result) # prints [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] [instruction] | Write a code for creating a Fibonacci sequence [input] | n = 10

[output] | The area of the circle with the radius of 4 is 50.26548245743669. [instruction] | Calculate the area of the circle with the radius of 4. [input] |

[output] | ABCXYZ, ABCXZY, ABYXZC, ABYZXC, ACBXYZ, ACBXZY, ACYXZB, ACYZXB, AXBZYC, AXBYCZ, AXYBCZ, AXYZBC, XABCYZ, XABCZY, XAYBZC, XAYCZB, XBACYZ, XBACZY, XBYACZ, XBYZAC, XYABCZ, XYAZBC. [instruction] | Write all the possible combinations for the strings, "ABC" and "XYZ". [input] |

[output] | [instruction] | Read the two given numbers and print the larger one. [input] | Number 1: 20 Number 2: 10

[output] | SELECT * FROM employees WHERE department = 'Marketing'; [instruction] | Create a SQL query that returns all employees in the "Marketing" department. [input] |

[output] | def dec_to_bin(n): binary_num = bin(n) print(binary_num[2:]) dec_to_bin(122) [instruction] | Write a Python script that converts the number 122 to binary. [input] |

[output] | function reverseString(str) { let reversed = "" for (let i = str.length-1; i >= 0; i--) { reversed += str[i] } return reversed } [instruction] | Create a JavaScript function that can take a string and reverse it. [input] |

[output] | my_dict = { "name": "John Smith", "age": 28, "location": "New York" } [instruction] | Create a Python dictionary that includes the keys "name", "age", and "location", and set the values to your name, age, and location. [input] |

[output] | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv [instruction] | Create an HTML page that uses Bootstrap to create a responsive navigation bar. [input] |

[output] | SELECT * FROM table_name WHERE email LIKE '%@%'; [instruction] | Write a SQL query that returns all records from a table where the value in the "email" column contains the "@" symbol. [input] |

[output] | my_array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] [instruction] | Create an array of 10 integers, starting from 0 and increasing with each element. [input] |

[output] | def checkPalindrome(inputString): # reverse the given string reverseString = inputString[::-1] # check if the string is equal to its reverse if (inputString == reverseString): return True else: return False # Driver code if __name__ == "__main__": [instruction] | Write a python script to identify a palindrome from a given input string [input] | inputString = "abacab"

[output] | public class MatrixMultiplication { public static void main(String []args) { int[][] matrix1 = { {1, 1}, {2, 2} }; int[][] matrix2 = { {1, 1}, {2, 2} }; int rows1 = matrix1.len [instruction] | Write a Java program to implement Matrix multiplication [input] |

[output] | function equalNumberOfPAndTCharacters(str){ let countP = 0; let countT = 0; for (let i = 0; i < str.length; i++) { if (str.charAt(i) == 'P') { countP++; } else if (str.charAt(i) == 'T') { countT++; } } if(countP == countT){ [instruction] | Write a JavaScript program to check if a given string contains equal number of P and T characters. [input] |

[output] | let dateString = "October 5, 2020"; let newDateString = dateString.substring(0, 3) + "/" + dateString.substring(8, 10) + "/" + dateString.substring(11); console.log(newDateString); //Output: 10/05/2020 [instruction] | Create a JavaScript program to convert the following date format into MM/DD/YYYY. [input] | dateString = "October 5, 2020"

[output] | //using 'split()' method String[] words = sentence.split("\\s+"); //split with regular expression int count = 0; for(String word: words){ count += word.length(); } System.out.println("The number of characters in the sentence is : "+count); //using 'replaceAll()' method int count = sentence.rep [instruction] | Write a java program to count the number of characters in a sentence without using a loop. [input] | sentence = "This is a simple sentence"

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