← 목록

Synth · CodeAlpaca일부

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

[output] | [ 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6 ] [instruction] | Create an array with values two and six repeated ten times. [input] |

[output] | A class is a blueprint from which individual objects are created, containing the attributes and behaviors of the objects. [instruction] | Concisely explain in one sentence what a class is in object-oriented programming. [input] |

[output] | dict_num_char = {num_list[i]: char_list[i] for i in range(len(num_list))} print(dict_num_char) [instruction] | Convert the list of numbers into a dictionary where the numeric values are the keys and the corresponding characters are the values. [input] | num_list = [1, 2, 3] char_list = ['a', 'b', 'c']

[output] | numbers = [] while True: user_input = input('input a number (input "done" to finish): ') if user_input.lower() == "done": break numbers.append(float(user_input)) avg = sum(numbers) / len(numbers) print('The average is', avg) [instruction] | Write a code to store the user input in a list and then find the average of the items in the list. [input] |

[output] | # Prime numbers between 2 and n n = int(input("Enter a positive integer: ")) # Initially assuming all integers between 2 and n are prime primeArray = [True] * (n + 1) # Create list of prime numbers for p in range(2, n+1): # If prime[p] is not changed, then it is a prime if primeArray[p] [instruction] | Edit the following code to allow for the user to input an unlimited list of numbers. [input] |

[output] | $sql = "SELECT page_name, view_count FROM pages ORDER BY view_count DESC LIMIT 5"; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { while($row = mysqli_fetch_assoc($result)) { echo "Page Name: " . $row["page_name"]. " - Views: " . $row["view_count"]. ""; } } else { e [instruction] | Write a code in PHP to display the top 5 most viewed pages in a website. [input] |

[output] | import java.util.Scanner; public class AreaOfTriangle { public static void main(String[] args) { double s; double area; Scanner sc = new Scanner(System.in); System.out.println("Enter the side of the equilateral triangle:"); s = sc.nextDouble(); ar [instruction] | Code a Java program to find the area of an equilateral triangle. [input] |

[output] | public int CountUppercase(string input_str) { // Initialize count int count = 0; // Count uppercase characters foreach (char c in input_str) { if (Char.IsUpper(c)) count++; } // R [instruction] | Use C# to create a function that takes in a string and count the number of uppercase characters within the string. [input] | <input_str="Hello World" >

[output] | function swapElements(x) { let temp = x[0]; x[0] = x[1]; x[1] = temp; } [instruction] | Create a function to swap two elements of an array in JavaScript. [input] | <x=[1, 2, 3, 4] >

[output] | def makeUpperCase(input_str): return input_str.upper() result = makeUpperCase("Hello World") print(result) [instruction] | Write a code in JavaScript to make all letters in a string upper case. [input] | <input_str="Hello World" >

[output] | #include <iostream> using namespace std; int main() { int n = 3; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) cout << i * j << " "; cout << endl; } return 0; } [instruction] | Create a C++ program to generate a multiplication table of size n x n. [input] | <n = 3>

[output] | <ul class="horizontal-list"> <li><a href="#" class="horizontal-item">Home</a></li> <li><a href="#" class="horizontal-item">About</a></li> <li><a href="#" class="horizontal-item">Contact</a></li> </ul> [instruction] | Using the code given below, add classes to the navigation links on the page to make them display horizontally instead of vertically. [input] | <ul> <li><a href="#">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Contact</a></li> </ul>

[output] | SELECT customer_id, item_id, quantity, (SELECT SUM(quantity) FROM orders WHERE customer_id = o.customer_id) AS total_Quantity FROM orders AS o; [instruction] | Using the SQL query given below, add a new column called 'total_Quantity' to the table output which is the sum of quantity of all the orders by customer_id [input] | SELECT customer_id, item_id, quantity FROM orders;

[output] | import re string = "Python is an interpreted, high-level, general-purpose programming language." substring = "general-purpose" second_occurrence = [(m.start(0)) for m in re.finditer(substring, string)][1] print('The second occurrence of the substring starts at index:', second_occurrence) [instruction] | Write a Python code snippet to find the index of the second occurrence of a substring in a given string. [input] | "Python is an interpreted, high-level, general-purpose programming language." "general-purpose"

[output] | <form action="/contact.php" id="contactForm" class="contactForm"> <input type="text" name="name"> <input type="email" name="email"> <input type="submit" value="Submit"> </form> [instruction] | Using the code snippet given below, add a class called contactForm to the HTML form. [input] | <form action="/contact.php" id="contactForm"> <input type="text" name="name"> <input type="email" name="email"> <input type="submit" value="Submit"> </form>

[output] | function removeElement(arr, index) { if (index >= 0 && index < arr.length) { arr.splice(index, 1); } return arr; } // Usage removeElement(arr, 2); // returns [1, 2, 4, 5] [instruction] | Write a JavaScript code to delete an item from an array. [input] | let arr = [1, 2, 3, 4, 5];

[output] | <ul> <li><a href="#" target="_blank">Home</a></li> <li><a href="#" target="_blank">About</a></li> <li><a href="#" target="_blank">Contact</a></li> </ul> [instruction] | Using the code given below, add JavaScript code to make the hyperlinks open in a new tab. [input] | <ul> <li><a href="#">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Contact</a></li> </ul>

[output] | <form action="/contact.php"> <input type="text" name="name"> <input type="email" name="email"> <input type="submit" value="Submit" class="btn"> </form> [instruction] | Using the code snippet given below, add a unique class called btn which will remove the default styles from the submit button. [input] | <form action="/contact.php"> <input type="text" name="name"> <input type="email" name="email"> <input type="submit" value="Submit"> </form>

[output] | <script> document.querySelectorAll('p').forEach(el => { el.style.backgroundColor = "#f0f0f0"; }); </script> <p>Paragraph 1</p> <p>Paragraph 2</p> [instruction] | Using the code snippet given below, write a JavaScript code to make the background color of the paragraphs "#f0f0f0". [input] | <p>Paragraph 1</p> <p>Paragraph 2</p>

[output] | <ul> <li><a href="#" class="active">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Contact</a></li> </ul> [instruction] | Using the code given below, add a class called "active" to the first navigation link to make it highlighted when the page is loaded. [input] | <ul> <li><a href="#">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Contact</a></li> </ul>

[output] | // States const IDLE = 'IDLE'; const COIN_INPUT = 'COIN_INPUT'; const SELECTION = 'SELECTION'; const DISPENSE = 'DISPENSE'; // Transitions const transitions = { [IDLE]: [COIN_INPUT], [COIN_INPUT]: [SELECTION], [SELECTION]: [DISPENSE], [DISPENSE]: [IDLE] }; // Actions const ENTER_ [instruction] | Build a state machine to simulate a vending machine. [input] |

[output] | import pymongo client = pymongo.MongoClient("mongodb://localhost:27017/") db = client["mydatabase"] collection = db["mycollection"] collection.insert_one({ "name": "John Doe", "age": 25, "city": "New York" }) [instruction] | Add the following content to the existing MongoDB database. [input] | { name: "John Doe", age: 25, city: "New York" }

[output] | SELECT name, grade, city FROM students WHERE grade < 50; [instruction] | Create a SQL query to return the information about the student's name, grade and city with the grade below 50. [input] |

[output] | let fruits = { "apple": 100, "banana": 200, "pear": 150 } let total_calorie = 0; Object.values(fruits).forEach(calorie => { total_calorie += calorie; }) [instruction] | Suggest a better design for the following JavaScript code to match the DRY principle. [input] | let calorie_per_apple = 100; let calorie_per_banana = 200; let calorie_per_pear = 150; let total_calorie = calorie_per_apple + calorie_per_banana + calorie_per_pear;

[output] | const express = require('express'); const app = express(); app.post('/myroute', (request, response) => { // Handle the POST request here }); [instruction] | Describe how to handle a POST request in Express. [input] |

[output] | class Zoo: def __init__(self): self.records = {} def add_record(self, animal, count): if animal in self.records: self.records[animal] += count else: self.records[animal] = count def get_count(self, animal): if animal in self.recor [instruction] | Create a class in Python that keeps the track records of animals in the zoo. [input] |

[output] | int arr[5]; for(int i=0; i<5; i++){ arr[i] = i*i; } [instruction] | Suggest what should be done to make the following C++ code more efficient. [input] | int arr[5]; for(int i=0; i<5; i++){ arr[i] = i; }

[output] | import requests # Make the API call url = "https://dummyapi.io/data/api/user" response = requests.get(url) # Fetch the information if response.status_code == 200: data = response.json() username = data['username'] email = data['email'] # Print the obtained info print(f'Username [instruction] | Create a script to fetch the information from the following API endpoint. [input] | https://dummyapi.io/data/api/user

[output] | let users = new Set(["John", "Sandy", "Stephen"]); if (users.has("John")) { console.log("John is present!"); } [instruction] | Suggest how would you use a Set in the following JavaScript code. [input] | let users = { "John": true, "Sandy": true, "Stephen": true }

[output] | SELECT * FROM customers WHERE last_name='Smith'; [instruction] | Suggest how to optimize the following MySQL query. [input] | SELECT * FROM customers WHERE last_name LIKE 'Smith';

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