← 목록

Synth · CodeAlpaca일부

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

[output] | square = lambda x: x*x #This lambda function will calculate the square of a number. [instruction] | Construct the lambda function for calculating the square of a number. [input] |

[output] | for index, element in enumerate(list_elements,start=1): print(index, element) #Output: #1 apple #2 banana #3 cherry [instruction] | Construct a for loop to print all the elements of a list numbered in sequence, as shown in the output. [input] | list_elements = ["apple", "banana", "cherry"]

[output] | len(string1) == len(string2) #This expression checks if the length of a string is equal to the length of another string. [instruction] | Construct an expression that checks if the length of a string is equal to the length of another string. [input] |

[output] | def print_list_elements(list): if len(list)>0: for element in list: print(element) else: print("The list has no elements.") #This edited code will print a statement if the given list has no elements. [instruction] | Edit the following code to print a statement if the given list has no elements. [input] | def print_list_elements(list): if len(list)>0: for element in list: print(element)

[output] | """ Create a tree structure using the Python dictionary provided """ class TreeNode: def __init__(self, value=None, parent=None, children=None): self.value = value self.parent = parent self.children = children if children is not None else [] def __repr__(self): [instruction] | Create a tree structure using the provided Python dictionary. [input] | dict = { 1: { 'parent': 0, 'children': [2, 3, 4] }, 2: { 'parent': 1, 'children': [] }, 3: { 'parent': 1, 'children': [5, 6] }, 4: { 'parent': 1, 'children': [7] }, 5: { 'parent': 3, 'children': [] }, 6: { 'parent': 3, 'children':

[output] | """ Write a Python code to calculate the maximum temperature for today based on a forecast of the seven-day forecast """ import datetime def get_max_temperature_today(forecast): today = datetime.datetime.today().weekday() max_temp = None for day in forecast: if day['day'] [instruction] | Write a Python code to calculate the maximum temperature for today based on a forecast of the seven-day forecast. [input] | forecast = [ {'day': 'Monday', 'description': 'sunny', 'temperature': 28}, {'day': 'Tuesday', 'description': 'sunny', 'temperature': 30}, {'day': 'Wednesday', 'description': 'cloudy', 'temperature': 28}, {'day': 'Thursday', 'description': 'raining', 'temperature': 25}, {'day': 'Friday', 'd

[output] | """ Create a function that sorts a dictionary of words and their frequencies alphabetically. """ def sort_dictionary(dictionary): return dict(sorted(dictionary.items(), key=lambda x: x[0])) if __name__ == "__main__": dict = { 'the': 10, 'at': 3, 'hello': 5, [instruction] | Create a function that sorts a dictionary of words and their frequencies alphabetically. [input] | dict = { 'the': 10, 'at': 3, 'hello': 5, 'cat': 1, 'counter': 2 }

[output] | """ Generate a HTML table which displays the elements of the array in the form of rows and columns. """ <!DOCTYPE html> <html> <head> <title>HTML Table</title> </head> <body> <table> <thead> <tr> <th>Name</th> [instruction] | Generate a HTML table which displays the elements of the array in the form of rows and columns. [input] | array = ["name, age, gender", "sara, 20, female", "john, 26, male"]

[output] | """ Write a Python program to group the values of a given list of elements based on the size of the elements. """ def group_values(values): result = {} for value in values: size = len(value) if size not in result: result[size] = [] result[size].append(val [instruction] | Write a Python program to group the values of a given list of elements based on the size of the elements. [input] |

[output] | """ Edit the provided JavaScript code such that it outputs the first and last element in an array. """ let array = ["a", "b", "c", "d", "e"]; console.log(`First element: ${array[0]}, Last element: ${array[array.length - 1]}`); [instruction] | Edit the provided JavaScript code such that it outputs the first and last element in an array. [input] | array = ['a', 'b', 'c', 'd', 'e']

[output] | """ Write a code to convert a given English sentence into Pig Latin. """ def pig_latin(sentence): vowel = ["a", "e", "i", "o", "u"] words = sentence.split(" ") pig_latin_words = [] for word in words: if word[0] in vowel: pig_latin_words.append(word + "way") [instruction] | Write a code to convert a given English sentence into Pig Latin. [input] |

[output] | def fibonacci_sequence(n): """Generate a Fibonacci sequence up to n.""" result = [] first, second = 0, 1 while first < n: result.append(first) first, second = second, first + second return result [instruction] | Add the following Python function to generate a Fibonacci sequence. [input] | def fibonacci_sequence(n): """Generate a Fibonacci sequence up to n."""

[output] | for i in range(11): print(i) [instruction] | Rewrite the following Python code so that it uses a for loop instead of a while loop. [input] | i = 0 while i < 11: print(i) i += 1

[output] | import pytz from datetime import datetime def get_time(): new_york = pytz.timezone('America/New_York') curr_time = datetime.now(new_york).strftime('%H:%M') return curr_time if __name__ == '__main__': print(get_time()) #this will print the current time in 24-hour format in New York [instruction] | Write a code to get the current time in New York City in 24-hour format. [input] |

[output] | def print_multiplication_table(): """Prints a multiplication table.""" # Print the header of the table print(' | '.join(str(i).ljust(4) for i in range(1, 11))) print('-' * 46) # Print the rows of the table for row in range(1, 11): print(' | '.join(str(row * col). [instruction] | Write code to print a multiplication table. [input] |

[output] | My name is Sam [instruction] | Given a sentence, remove all special characters. [input] | My@name*is¥Sam

[output] | SELECT studentName FROM Student WHERE major IS NULL; [instruction] | Compose a SQL query to retrieve the names of all students that have no assigned major. [input] | Student

[output] | import tensorflow as tf # Define the model. model = tf.keras.models.Sequential([ tf.keras.layers.Dense(10, activation="relu"), tf.keras.layers.Dense(1) ]) # Compile the model. model.compile(optimizer="adam", loss="mse") # Train the model. model.fit([1, 2, 3], [8.5], epochs=50) [instruction] | Use a Tensorflow model to predict a numerical output from an input. [input] | Input: [1, 2, 3] Output: 8.5

[output] | public class DistinctElements { public static void main(String[] args) { int[] arr = {1, 2, 3, 2, 1, 4, 3, 2}; // Initialize all element with the value 0. int[] temp = new int[arr.length]; int visited = -1; for (int i = 0; i < arr.length; i++) [instruction] | Create a Java program to count and print the distinct elements in an array. [input] | int[] arr = {1, 2, 3, 2, 1, 4, 3, 2}

[output] | SELECT COUNT(*) FROM Student WHERE GPA > 3.5; [instruction] | Compose a SQL query to find the number of students whose GPA is greater than 3.5. [input] | Student

[output] | import requests def get_api_data(): url = 'http://jsonplaceholder.typicode.com/users' response = requests.get(url) return response.json() if __name__ == '__main__': data = get_api_data() print(data) [instruction] | Using the "requests" library, write a code to get the data from the endpoint http://jsonplaceholder.typicode.com/users [input] |

[output] | import json resp = '[{"name": "john", "age": 25}, {"name": "Anna", "age": 17}, {"name": "Rick", "age": 46}]' data = json.loads(resp) print(len(data)) # 3 objects [instruction] | Parse the following JSON string and print out how many objects are there? [input] | resp = '[{"name": "john", "age": 25}, {"name": "Anna", "age": 17}, {"name": "Rick", "age": 46}]'

[output] | def remove_duplicates(arr): result = [] for num in arr: if num not in result: # if current element is unique, add to the list. result.append(num) return result new_arr = remove_duplicates(arr) print(new_arr) # [1, 2, 3, 4, 5, 6, 7] [instruction] | Create another function to remove duplicates from the array. [input] | arr = [1, 1, 2, 3, 4, 5, 5, 6, 7]

[output] | def find_longest_substring(string): # get the length of the string length = len(string) # variable to store the longest substring length longest_substring_length = 0 # variable to store the longest substring longest_substring = '' # loop through the stri [instruction] | Suggest a code to find the longest sub-string in a string. [input] | string = "The quick brown fox jump over lazy dog"

[output] | if x * y < 0: [instruction] | Reformat the following if statement so that it has only one condition. [input] | if (x < 0 and y >= 0) or (x >= 0 and y < 0):

[output] | import asyncio async def calculate_sum(numbers): result = 0 for num in numbers: result += num await asyncio.sleep(2) return result [instruction] | Convert this program into an AsyncIO based one. [input] | import time def calculate_sum(numbers): result = 0 for num in numbers: result += num time.sleep(2) return result

[output] | def calculate_total(discounts): total = 0 for discount in discounts: total -= total * (discount / 100) return total [instruction] | Create a function to calculate the total cost after N discounts. [input] | discounts = [10, 15, 20]

[output] | SELECT (max(people.age)-min(people.age)) as age_difference FROM people; [instruction] | Write a SQL query to find the age difference between two people in a table. [input] | Table: "people" | name | age | |------|-----| | John | 30 | | Jane | 25 |

[output] | const char* str1 = "Hello"; const char* str2 = "World!"; [instruction] | Reformat the following C++ code to reduce the memory it needs to function. [input] | char str1[] = "Hello"; char str2[] = "World!";

[output] | class MortgageCalculator: def __init__(self, principle, years, rate): self.principle = principle self.years = years self.rate = rate def calculate_mortgage(self): # calculation return monthly_payment def calculate_interest_rate(self, value): [instruction] | Convert this program from procedural to object-oriented. [input] | def calculate_mortgage(principle, years, rate): # calculation return monthly_payment def calculate_interest_rate(value): # calculation return interest_rate

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