← 목록

Synth · CodeAlpaca일부

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

[output] | def identify_odd_even(num): if num % 2 == 0: return "even" else: return "odd" [instruction] | Identify if a given integer is odd or even. [input] | 43

[output] | import random def random_code_string(length): chars = [chr(i) for i in range(65, 91)] + [str(digit) for digit in range(10)] code_string = "" for _ in range(length): random_char = random.choice(chars) code_string += random_char return code_string [instruction] | Generate a random code string with each character from A-Z and 0-10. [input] |

[output] | def find_duplicates(arr): duplicates = [] seen = set() for elem in arr: if elem in seen: duplicates.append(elem) else: seen.add(elem) return duplicates [instruction] | Find all duplicates in an array. [input] | arr = [1, 2, 4, 2, 1, 5]

[output] | def merge_objects(obj_a, obj_b): merged = {**obj_a, **obj_b} return merged [instruction] | Create a function that takes two parameters and merge them into a single object. [input] | a = {'a': 1, 'b': 2} b = {'c': 3, 'd': 4}

[output] | import set a = [1, 1, 2, 3, 4, 5, 5, 5] a_set = set(a) new_list = list(a_set) print(new_list) [instruction] | Rewrite the following code using the set module in Python [input] | a = [1, 1, 2, 3, 4, 5, 5, 5]

[output] | # Code to convert Celsius to Fahrenheit def c_to_f(celsius): return celsius * 9/5 + 32 # Create a web service from flask import Flask app = Flask(__name__) @app.route('/converter/<list:celsius>', methods =['GET']) def convert_celsius(celsius): # Convert the Celsius values to Fahrenheit [instruction] | Create a web service to convert a given list of temperatures from Celsius to Fahrenheit. [input] | [50, 51, 52, 53, 54]

[output] | # Program to generate a random password of 10 characters import string import random # Get all the symbols to use in the password symbols = string.ascii_letters + string.digits # Generate a random password password = ''.join(random.choice(symbols) for _ in range(10)) print(password) [instruction] | Create a program to generate a random password of 10 characters consisting of both alphabets and numbers. [input] |

[output] | # Program to encode a message with the Caesar cipher encryption algorithm # Get the message to encrypt message = 'Hello World' # Set the shift value shift = 3 # Create an array to store the encrypted message encrypted_message = [] for character in message: encrypted_character = chr(ord(c [instruction] | Create a program to encode a message with the Caesar cipher encryption algorithm. [input] | message = 'Hello World' shift = 3

[output] | # Program to generate a simple web page from flask import Flask, request app = Flask(__name__) # Render the web page @app.route('/', methods = ['GET']) def show_index_page(): return ''' <html> <head> <title>Greeting Form</title> </head> <body> <h1>Greeting Form</h1> [instruction] | Generate a web page with a form that takes a user's name and age, and outputs a greeting based on the age. [input] |

[output] | # Program to simulate a random walk in two-dimensional space import random x_steps = 10 # Initialize starting positions x = 0 y = 0 # Take a random step on each iteration for _ in range(x_steps): direction = random.randint(0, 3) if direction == 0: x += 1 elif direction == 1: x -= 1 [instruction] | Write a code to simulate a random walk in two-dimensional space. [input] | x_steps = 10

[output] | # Program to implement a round-robin scheduling algorithm # Get the list of processes and the time slice processes = [10, 5, 7] time_slice = 2 # Create an empty list to store the remaining burst time remaining_burst = [] # Loop through all processes to get the remaining burst time for process [instruction] | Write a code to implement a round-robin scheduling algorithm. [input] | processes = [10, 5, 7] time_slice = 2

[output] | # Program to create a n-dimensional array filled with zeros import numpy as np # Get the number of dimensions n = 4 # Create an array of zeros of given size arr = np.zeros((n,n,n,n)) print(arr) [instruction] | Generate a python program to create a n-dimensional array filled with zeros. [input] | n = 4

[output] | average = 5.4 [instruction] | You need to compute the Average of all numbers stored in an array [input] | arr = [3, 2, 5, 9, 6]

[output] | class Circle: def __init__(self, radius): self.radius = radius def area(self): return 3.14 * (self.radius**2) def circumference(self): return 2 * 3.14 * self.radius [instruction] | Create a class named 'Circle' which calculates the area and circumference given a radius. [input] |

[output] | True [instruction] | Write a function that takes two strings as input,one being a base string and other being a sub-string and returns True if sub-string appears in base string and False otherwise. [input] | Base string = "I am a coding enthusiast" Sub-string = "coding"

[output] | thiic ng Chal [instruction] | You need to extract a part of the string from the starting to the 5th character and from 7th to the 25th character. [input] | string = "This is a coding challenge"

[output] | 9 [instruction] | You need to find the number of words in a sentence. [input] | sentence = "The quick brown fox jumps over the lazy dog"

[output] | dictionary = { 'Apple': 'Red', 'Banana': 'Yellow', 'Strawberry': 'Red', 'Orange': 'Orange', 'Grape': 'Purple' } [instruction] | Generate a dictionary with five key-value pairs of string. [input] |

[output] | [1, 3, 4, 5, 6, 7, 8] [instruction] | Sort an array using bubble sort technique. [input] | arr = [4, 3, 6, 7, 5, 1, 8]

[output] | "Hello, my name is John Doe." [instruction] | Output a sentence in the following format with 'name' as the user input. [input] | name = 'John Doe'

[output] | [2, 3, 6, 8] [instruction] | Take an array and remove all elements except the unique elements. [input] | arr = [2, 3, 6, 8, 3, 8, 6, 2]

[output] | Hello John. [instruction] | Take user input from the console and output 'Hello [name]'. [input] | name = 'John'

[output] | gnimmargorP [instruction] | Take a string and reverse it. [input] | string = 'Programming'

[output] | # define the Employee class class Employee: # construct a new Employee instance def __init__(self, id, name): self.id = id self.name = name # create a new Employee object employee1 = Employee(1, "John Doe") # access the employee id and name print(employee1.id) print(employe [instruction] | Create a Python class called Employee which contains the employee id and the name. [input] |

[output] | # define a function to combine two lists into one def combine_lists(list_1, list_2): # create a new list combined_list = [] # append the elements from list 1 for ele in list_1: combined_list.append(ele) # append the elements from list 2 for ele in list_2: [instruction] | Create a program that takes in two lists and prints out a new list with the elements from the first list followed by the elements from the second list. [input] | list_1 = [1, 2, 3] list_2 = [4, 5, 6]

[output] | def solve_eq(x, y, z): '''This function will solve the equation: x^2 + y^2 = z^2.''' # Use the Pythagorean Theorem if x**2 + y**2 == z**2: return True else: return False [instruction] | Implement a function to solve the following equation: x2+y2=z2 [input] |

[output] | def find_indices(num): # convert given number to binary binary_num = bin(num)[2:] # create an empty list to store required indices indices_list = [] # iterate over the binary number for i in range(len(binary_num)-1): if binary_num[i+1] != '1' or binary_num[i] != [instruction] | Complete the following function to return the indices at which the binary representation of a given number has no consecutive 1s. [input] | num = 12

[output] | def remove_consecutive_chars(string): # create an empty string new_string = '' # iterate over the characters of the given string for i in range(len(string)-1): if string[i] != string[i+1]: new_string += string[i] # add the last character of the string to the output new_stri [instruction] | Given a string, write code to remove all the consecutive characters and output the new string. [input] | string='AAABBBCCC'

[output] | import re def is_valid_ipv4(ip): # pattern to match valid IP addresses pattern = r"^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$" if re.match(pattern, ip): return T [instruction] | Create a regex to identify valid IPV4 addresses. [input] |

[output] | def generate_permutations(n): if n == 0: return [] if n == 1: return [[1]] permutations = [] for i in range(n): permutations_n_1 = generate_permutations(n - 1) for perm in permutations_n_1: for j in range(n): [instruction] | Write a function to generate an array of all possible permutations of N numbers. [input] |

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