← 목록

Synth · CodeAlpaca일부

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

[output] | def bubble_sort(arr): arr_length = len(arr) # Iterate through entire array for i in range(arr_length): # Iterate through unsorted subarray for j in range(0, arr_length-i-1): # Swap items if needed if arr[j] > arr[j+1] : arr[j] [instruction] | Construct a sorting algorithm to sort an array in increasing order. [input] | array = [4,7,1,3,9]

[output] | import string import random def random_string_generator(n): letters = string.ascii_letters return ''.join(random.choice(letters) for i in range(n)) [instruction] | Create a function that generates a random string of length n using alphabet characters. [input] |

[output] | class Fibonacci: def __init__(self, num): self.num = num def fibo(self): prev = 0 current = 1 next = 0 print(prev) print(current) for i in range(2,self.num): next=prev+current print(next) prev=curre [instruction] | Create an object oriented program to print the Fibonacci sequence. [input] |

[output] | def fibonacci(n): # Creating an array to store the sequence f = [0] * (n + 2) # Initial values f[1] = 1 # Calculating the terms for i in range(2, n + 2): f[i] = f[i - 1] + f[i - 2] return f[1:n+1] n = 10 print(fibonacci(n)) [instruction] | Print out the first 10 elements in the sequence interpreted by the rule F(n) = F(n-1) + F(n-2). [input] |

[output] | class ReverseNumber(): def __init__(self): pass def reverse_number(self, num): reverse = 0 # Iterate over the given number while(num > 0): reminder = num % 10 # Constructing the reverse number reverse [instruction] | Design a class in python to find the reverse of a number. [input] |

[output] | def sum_elements(arr): sum = 0 for i in range(len(arr)): for j in range(len(arr[i])): sum += arr[i][j] return sum [instruction] | Generate a syntax-correct program to calculate the sum of the elements in a given 2D array [input] |

[output] | def reverse_list(head): curr = head prev = None while curr is not None: next_ = curr.next curr.next = prev prev = curr curr = next_ head = prev return head [instruction] | Generate a syntax correct program which reverses a given linked list [input] |

[output] | <!DOCTYPE html> <html> <head> <title>Sample Form</title> </head> <body> <form action="" method="post"> <input type="text" placeholder="Input..."/> <input type="submit" value="Submit" /> </form> </body> </html> [instruction] | Construct a HTML page that displays a form with a text field and a submit button. [input] |

[output] | import java.util.Random; public class RandomArray { public static void main(String[] args) { Random rand = new Random(); float array[] = new float[10]; for(int i = 0; i < 10; i++) { array[i] = rand.nextFloat(); } System.out.prin [instruction] | Write a code to create an array of 10 random numbers between 0 and 1. [input] |

[output] | <html> <head> <title>Sample Page</title> </head> <body> <h1 style="text-align: center;">Heading</h1> </body> </html> [instruction] | Edit this HTML page to make the page have a centered heading [input] | <html> <head> <title>Sample Page</title> </head> <body> <h1>Heading</h1> </body> </html>

[output] | #include <iostream> #include <math.h> using namespace std; int main() { float area, s, a, b, c; // caluculate the semi-perimeter s = (a + b + c) / 2; // calculate the area area = sqrt(s * (s - a) * (s - b) * (s - c)); // check whether triangle is possible or not [instruction] | Create a C++ program to create a triangle with an area of 10. [input] |

[output] | [1, 3, 4, 7, 10, 19] [instruction] | Arrange the following data for sorting operation. [input] | [4, 19, 10, 7, 1, 3]

[output] | function longestString(arr) { let longest = ''; arr.forEach(string => { if (string.length > longest.length) { longest = string; } }); return longest; } [instruction] | Create a JavaScript function to return the longest string from an array. [input] | arr = ["Hi", "Hello", "Good Morning"]

[output] | class CountObjects: count = 0 def __init__(self): CountObjects.count += 1 @classmethod def get_count(cls): return cls.count [instruction] | Create a class in Python thattracks the number of objects created. [input] |

[output] | SELECT COUNT(*) FROM students WHERE name='John'; [instruction] | Write an SQL query to count the number of records from a table named 'students' with a particular name. [input] | name='John'

[output] | The operator to compare two strings in a programming language is '===' (strict equality operator). [instruction] | What operator should be used to compare two strings in a programming language? [input] |

[output] | let currentURL = window.location.href; console.log(currentURL); [instruction] | Write a code snippet to display a website's current URL. [input] |

[output] | switch (num) { case 1: console.log('one'); break; case 2: console.log('two'); break; case 3: console.log('three'); break; case 4: console.log('four'); break; case 5: console.log('five'); break; case 6: console.log('six'); break; case 7: [instruction] | Create a switch statement to display the corresponding number in words. [input] | 6

[output] | The apple is red. [instruction] | Edit the sentence using the correct punctuation. [input] | The apple is red

[output] | let lowerCaseText = text.toLowerCase(); console.log(lowerCaseText); // lowercasing [instruction] | Write a code snippet to convert the text to lowercase. [input] | LOWERCASING

[output] | function camelCaseToSnakeCase(str){ let result = str[0].toLowerCase(); for (let i = 1; i < str.length; i++) { if (str.charAt(i) === str.charAt(i).toUpperCase()) result += "_" + str.charAt(i).toLowerCase(); else result += str.charAt(i); } return result; } [instruction] | Write a JavaScript function to convert a CamelCase string to a snake_case string. [input] | CamelCaseStr

[output] | public static int getLargestElement(int[] nums){ int largest = nums[0]; for(int i = 1; i < nums.length; i++){ if(nums[i] > largest){ largest = nums[i]; } } return largest; } [instruction] | Write a Java method to return the largest element from an array of integers. [input] | [4, 8, 3, 10, 6]

[output] | class Book { private int ISBN; private String title; private List<String> authors; private int year; public Book(int ISBN, String title, List<String> authors, int year) { this.ISBN = ISBN; this.title = title; this.authors = authors; this.year = year; } //ge [instruction] | Create a data structure in Java to store books and their associated information like ISBN, authors, etc. [input] |

[output] | SELECT employees.* FROM employees JOIN departments ON departments.id = employees.department_id WHERE department_name = 'Sales and Marketing'; [instruction] | Write a MySQL query to join employees and departments tables and retrieve records which have department_name='Sales and Marketing'. [input] |

[output] | Area of the parallelogram = 40 m2 [instruction] | Calculate the area of a parallelogram with base lengths 5m and 8m and height of 4m. [input] |

[output] | ^[a-zA-Z_$][\w$]*$ [instruction] | Write a REGEX pattern to only match valid JavaScript variable names. [input] |

[output] | tasks = [t for t in tasks if not t.completed] [instruction] | Refactor this line of code to make it more concise. [input] | tasks = [t for t in tasks if t.completed == False]

[output] | def print_indices(x, arr): indices = [] for i in range(len(arr)): if arr[i] == x: indices.append(i) return indices print(print_indices(x, arr)) # [1, 4] [instruction] | Implement a code to print the indices of all occurrences of a number x in an array arr. [input] | x = 5 arr = [1, 5, 2, 8, 5, 10]

[output] | def combo(list1, list2): result = [] for i in list1: for j in list2: result.append((i, j)) return result combos = combo(list1, list2) # [(1, 5), (1, 6), (1, 7), (1, 8), (2, 5), (2, 6), (2, 7), (2, 8), (3, 5), (3, 6), (3, 7), (3, 8), (4, 5), (4, 6), (4, 7), (4, 8)] [instruction] | Write code to create a list of tuples that contains all the possible combinations of two elements taken from two different lists. [input] | list1 = [1, 2, 3, 4] list2 = [5, 6, 7, 8]

[output] | def sum_positive(arr): result = 0 for num in arr: if num != 0: result += abs(num) return result [instruction] | Edit this piece of code to work with negative numbers [input] | def sum_positive(arr): result = 0 for num in arr: if num >= 0: result += num return result

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