← 목록

Synth · CodeAlpaca일부

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

[output] | twoDArray = [[0,0,0,0,0], [0,0,0,0,0], [0,0,0,0,0], [0,0,0,0,0], [0,0,0,0,0]] [instruction] | Create and initialize a two-dimensional array of size 5x5 with 0s. [input] |

[output] | def gcd(a, b): if a == 0 : return b return gcd(b % a, a) [instruction] | Generate a function to check for the largest common divisor between two numbers. [input] |

[output] | class UniqueID: count = 0 def __init__(self): UniqueID.count+=1 self.id = UniqueID.count [instruction] | Design a class that can create objects with a unique ID. [input] |

[output] | import re MIN_LENGTH = 8 MAX_LENGTH = 15 def is_valid_password(password): #check password length if len(password) < MIN_LENGTH or len(password) > MAX_LENGTH: return False #check for at least one digit if re.search(r"[0-9]",password) is None: return False [instruction] | Design a password validation system using Python code. [input] |

[output] | <html> <head> <title>Top 10 Trending Movies of the Year</title> </head> <body> <h1>Top 10 Trending Movies of the Year</h1> <ul> <li>Avengers: Endgame</li> <li>Captain Marvel</li> <li>Spider-Man: Far From Home</li> <li>Toy Story 4</li> <li>Joker</li> [instruction] | Generate a web page which shows the top 10 trending movies of the year. [input] |

[output] | def get_average(list_of_numbers): """Returns average of the given list of numbers""" if list_of_numbers: return sum(list_of_numbers)/len(list_of_numbers) return list_of_numbers = [1, 4, 5, 6, 8] average = get_average(list_of_numbers) print(average) # 5 [instruction] | Modify this code to make it a function which takes a list of numbers and returns their average. [input] | list_of_numbers = [1, 4, 5, 6, 8]

[output] | import string import random def generate_password(): # get all letters and digits chars = string.ascii_letters + string.digits + string.punctuation # generate a 8 character password from chars password = ''.join(random.sample(chars, 8)) return password # example password = ge [instruction] | Generate a random password which contains 8 characters including characters, digits, and symbols. [input] |

[output] | class SingletonClass: _instance = None def __new__(self): if not self._instance: self._instance = super().__new__(self) return self._instance # testing obj1 = SingletonClass() obj2 = SingletonClass() if obj1 is obj2: print('obj1 and obj2 are the same insta [instruction] | Create a singleton class. [input] |

[output] | def add_key_value_pair(my_dict, key, value): """Adds the given key value pair to the dictionary""" if key not in my_dict: my_dict[key] = value return my_dict my_dict = {'name': 'John'} key = 'age' value = 18 updated_dict = add_key_value_pair(my_dict, key, value) print(updated_d [instruction] | Convert this code to a function which takes a dictionary as an argument and adds the given key value pair to it. [input] | my_dict = {'name': 'John'} key = 'age' value = 18

[output] | def fibonacci(n): """Prints the fibonacci series till the nth term""" # set initial values a = 0 b = 1 # check for valid input if n < 0: print('Please enter a positive number') elif n == 0: print('0') elif n == 1: print('0, 1') else: [instruction] | Edit this code to make the function take an integer n as an argument and print the fibonacci series till nth term. [input] | n = 10

[output] | let user = { name: "John", age: 25 }; [instruction] | Use JS to create an object called `user` which contains two properties: `name` with a string value of "John", and `age` with a numeric value of 25. [input] |

[output] | li.list-item { } [instruction] | Write a CSS selector to select all the list items with class "list-item". [input] |

[output] | <input type="text" placeholder="Type something here" /> [instruction] | Write HTML to create an input element with placeholder text "Type something here". [input] |

[output] | $('.closed').hide(); [instruction] | Write a jQuery expression to hide all the elements with class "closed". [input] |

[output] | SELECT * FROM products ORDER BY price DESC LIMIT 5; [instruction] | Write an SQL query to select the first five items from a table called 'products' sorted by price in descending order. [input] |

[output] | str_upper_case = str_lower_case.upper() [instruction] | Write a code in Python to convert a string of text to its equivalent uppercase characters. [input] | str_lower_case = "hello world"

[output] | def power_calc(base, exponent): return base ** exponent [instruction] | Define a function that takes in two numbers, and calculates the power of the first number raised to the power of the second number. [input] | base = 3 exponent = 4

[output] | def count_words(sentence): word_count = {} for word in sentence.split(): if word in word_count: word_count[word] += 1 else: word_count[word] = 1 return word_count count_words(sentence) [instruction] | Create a code that takes in a sentence and outputs counts of each word and its frequency (how often it occurred). [input] | sentence = "This is an example sentence to test the word count code."

[output] | def get_even_numbers(numbers): even_numbers = [] for number in numbers: if number % 2 == 0: even_numbers.append(number) return even_numbers get_even_numbers(numbers) [instruction] | Create a code that take an input of the list of integers, and outputs even numbers from the list. [input] | numbers = [2, 3, 4, 5, 6, 7, 8]

[output] | def row_sum(matrix): row_sums = [] for row in matrix: row_sum = 0 for col in row: row_sum += col row_sums.append(row_sum) return row_sums row_sum(matrix) [instruction] | Create a code to input a 2D matrix and output the sum of each row. [input] | [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

[output] | def name_length_dict(names): name_length_dict = dict() for name in names: name_length_dict[name] = len(name) return name_length_dict name_length_dict(names) [instruction] | Write a code that takes in a list of names and creates a dictionary with the names as keys and their lengths as values. [input] | names = ["Mary", "John", "Mike"]

[output] | def count_vowels(sentence): vowels = ['a', 'e', 'i', 'o', 'u'] count = 0 for char in sentence.lower(): if char in vowels: count += 1 return count count_vowels(sentence) [instruction] | Create a code to input a sentence and output the number of vowels in the sentence. [input] | sentence = "This is a sentence with vowels."

[output] | def merge_strings(strings): merged_string = '' for string in strings: merged_string += string return merged_string merge_strings(strings) [instruction] | Create a code which takes in a list of strings, and returns a string with all the characters of the strings sequentially. [input] | strings = ["Hello", "World"]

[output] | class Employee: def __init__(self, id, name, salary, job_title): self.id = id self.name = name self.salary = salary self.job_title = job_title [instruction] | Create a class in Python to represent an employee and define the attributes. [input] |

[output] | import pandas as pd df = pd.read_sql_query('''SELECT Country, COUNT(*) as Total_Orders FROM Orders GROUP BY Country''', conn) df.groupby('Country').agg({'Total_Orders':['count']}) [instruction] | Convert the following SQL query to Pandas to group the data by Country. [input] | SELECT Country, COUNT(*) as Total_Orders FROM Orders GROUP BY Country

[output] | import platform def test_windows(): if platform.system() != 'Windows': return # Do test [instruction] | Modify the following code to skip the test if the platform is not windows. [input] | import platform def test_windows(): if platform.system() == 'Windows': # Do test

[output] | import datetime def convert_date_string(date_string): return datetime.datetime.strptime(date_string, "%d-%m-%y") [instruction] | Suggest a completion for the following to convert a date string to datetime format. [input] | import datetime def convert_date_string(date_string):

[output] | my_list = [1, 2, 3] result = list(map(lambda x: x ** 2, my_list)) [instruction] | Suggest a completion for achieving the following without using a `for` loop. [input] | my_list = [1, 2, 3] # Do something

[output] | my_dict = {"name": "John", "age": 27} if "name" in my_dict: print("Key present") [instruction] | Suggest a completion for the following to check if a given key exists in a dictionary or not. [input] | my_dict = {"name": "John", "age": 27} # Do something

[output] | # Connect to MySQL import mysql.connector # Establish database connection mydb = mysql.connector.connect( host="localhost", user="GPTuser", passwd="GPT123", database="GPT" ) print(mydb) [instruction] | Establish a database connection using the inputs given. [input] | hostname: localhost username: GPTuser password: GPT123 database: GPT

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