text stringlengths 141 2.89k ⌀ | instruction stringlengths 19 1.5k ⌀ | input stringlengths 0 800 ⌀ | output stringlengths 1 2.5k ⌀ |
|---|---|---|---|
null | Perform an left outer join of two tables, Customers and Orders, in an SQL query and order the result by CustomerName in ascending order. | SELECT c.Name AS CustomerName, o.OrderNumber FROM Customers c LEFT OUTER JOIN Orders o ON c.ID = o.CustomerID ORDER BY CustomerName ASC; | |
null | Write a Python program to find a pair of elements (from an array) whose sum is an exact number. | [2, 4, 6, 9], 8 | def sum_pair(array, target_sum):
res_pair = []
# Sort the array
array.sort()
# Set the left and right pointers
l, r = 0, len(array) - 1
while l != r:
if array[l] + array[r] == target_sum:
res_pair.append((array[l], array[r]))
l += 1
r -= 1
... |
null | Create an HTML form with a submit button that will trigger an alert message on clicking the button. | <form action="" method="post"> <input type="submit" value="Submit" onclick="alert('Form submitted!')"/> </form> | |
null | Design a class Car with a constructor to initialize the variables _type, _year and _color | class Car: def __init__(self, type, year, color): self._type = type self._year = year self._color = color | |
null | Create a Python function to swap key-value pairs in a dictionary. | def swap_dict_keys(d): return {v: k for k, v in d.items()} | |
[DE Wikipedia] Smithy Clough
Der Smithy Clough ist ein Wasserlauf in Lancashire, England. Er entsteht als Nan Hole Clough an der Nordostseite des Boulsworth Hill und fließt in nordwestlicher Richtung. Er bildet bei seinem Zusammentreffen mit dem Turnhole Clough den Wycoller Beck. Gewässer in Lancashire | null | null | null |
[HI Wikipedia] संगीत
सुव्यवस्थित ध्वनि, जो रस की सृष्टि करे, संगीत कहलाती है। गायन, वादन व नृत्य तीनों के समावेश को संगीत कहते हैं। संगीत नाम इन तीनों के एक साथ व्यवहार से पड़ा है। गाना, बजाना और नाचना प्रायः इतने पुराने है जितना पुराना आदमी है। बजाने और बाजे की कला आदमी ने कुछ बाद में खोजी-सीखी हो, पर गाने और नाचने क... | null | null | null |
null | Given a n x n matrix where each element is 0 or 1, how can you find the area of the largest square sub-matrix composed of only ‘1s’? | The simplest way to find the area of the largest square sub-matrix composed entirely of '1's is to use a dynamic programming approach. The algorithm works by iterating through all the elements in the matrix. At each cell, it checks if the current element is a '1' and if the other elements around it form a square sub-ma... | |
null | Write a C++ function that generates a Fibonacci series of numbers up to an integer n. | n = 8 | #include <iostream> using namespace std; int Fibonacci (int n){ if (n<=0) return 0; if (n==1) return 1; else return Fibonacci(n-1)+Fibonacci(n-2); } int main() { int n; cin >> n; for (int i=0;i <n; i++){ cout << Fibonacci(i) << " "; } return 0; } |
null | Write a Python script to generate a random password string with length 20 that contains all the characters in the string. | import random
def generate_password(length):
password_str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+"
password = "".join(random.sample(password_str,length ))
return password
# Driver Code
length = 20
print(generate_password(length)) | |
null | Write a Python program to extract odd elements from a list. | mylist = [2, 3, 4, 5, 6, 7, 8] | mylist = [2, 3, 4, 5, 6, 7, 8]
odd_list = []
for num in mylist:
if num % 2 != 0:
odd_list.append(num)
print(odd_list) #[3, 5, 7] |
null | Use HTML to create a webpage with a text input field and a button. | <html> <body> <input type="text" id="text_input" /> <button onclick="handleInput()">Submit</button> </body> </html> | |
null | Create a python program to filter a list of numbers to include only the prime numbers | [2, 3, 7, 11, 12, 15] | def isPrime(n):
for i in range(2,n):
if n % i == 0:
return False
return True
numbers = [2, 3, 7, 11, 12, 15]
primes = filter(isPrime, numbers)
print('Prime numbers are:')
print(list(primes)) |
null | Create a dictionary from a list of tuples, where the key is the first element of the tuple and the value is the second element of the tuple. | list_of_tuples = [('key1', 'val1'), ('key2', 'val2'), ('key3', 'val3')] | def list_to_dict(list_of_tuples): return dict(list_of_tuples) |
null | Design a program in Python that will count the words in a sentence. | This is a sample sentence. | def word_count(sentence): words = sentence.split(' ') return len(words) print(word_count('This is a sample sentence.')) |
null | Create an HTML form that contains a text box and a submit button. | <form> <input type="text" name="inputText"> <input type="submit" value="Submit"> </form> | |
null | Find the total number of elements in the following array. | my_array = [[1,2], 3, 4] | Total number of elements = 4 |
null | Create a Python function to sort a list of strings based on a given alphabetical order. | alphabet = 'bdhajfz', strings = ['bad', 'hfja', 'abd', 'zaj'] | def sort_string_list(strings, alphabet): sorted_list = sorted(strings, key=lambda x:(alphabet.index(x[0]),x)) return sorted_list |
null | Train an XGBoost model in Python to classify emails into two categories: 'spam' and 'not spam'. | Data set with 4,000 emails | import pandas as pd
import xgboost as xgb
# Read in the data set
data = pd.read_csv('email.csv')
# Split the data into features and labels
X = data.drop(columns=['label'])
y = data['label']
# Train and test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Build the m... |
null | Write a JavaScript program that asks the user to enter a number and then prints the sum of the cube of the digits of the number. | let number = Number(prompt("Enter a number:")); let sum = 0; while (number > 0) { let last_digit = number % 10; sum = sum + last_digit**3; number = (number - last_digit)/10; } console.log(sum); # The output will be the sum of the cube of the digits | |
[DE Wikipedia] Munichion
Munichion ( oder ) war ein Monat des attischen Kalenders. Er war der zehnte Monat des attischen Kalenders, im julianischen Kalender entspricht ihm etwa der März/April. Plutarch zufolge wurde der Name zu Ehren von Demetrios I. Poliorketes am Ende des 4. Jahrhunderts v. Chr. in Demetrion geänder... | null | null | null |
null | Create a Java class to find all substrings of a given string. | String str = "Hello World" | public class SubstringFinder { public static List<String> findSubstrings(String str) { List<String> substrings = new ArrayList<>(); for (int i = 0; i < str.length(); i++) { for (int j = i + 1; j <= str.length(); j++) { String substr = str.substring(i, j); substrings.add(substr); } } return substrings; } } String str = ... |
null | Optimize an existing Python script to run as efficiently as possible. | def spam(divideBy):
return 42 / divideBy
print(spam(2))
print(spam(12))
print(spam(0)) | def spam(divideBy):
try:
return 42 / divideBy
except ZeroDivisionError:
print('Error: Invalid argument.')
print(spam(2))
print(spam(12))
print(spam(0)) |
null | Develop a function in Python that takes an integer as an argument and prints the factorial of the number. | def factorial(n):
"""Computes the factorial of a number
Parameters
----------
n : int
The number
Returns
-------
factorial : int
The factorial of the number
"""
if n < 0:
return 0
elif n == 0 or n == 1:
return 1
else:
factorial = ... | |
[CS Wikipedia] Pavillon des Arts
Pavillon des Arts (Pavilon umění) byla galerie umění v Paříži. Nacházela se v 1. obvodu v ulici Rue Rambuteau. Historie Pavilon byl založen v roce 1983 a uzavřen roku 2006. Výstavy Galerie se zaměřovala na umění ve všech jeho formách, různých kultur a různých období: fotografie, malířs... | null | null | null |
null | Create a basic Python Flask application that takes a number as input from a form and displays its increment by 1. | Not applicable | from flask import Flask, request, render_template
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
number = int(request.form['number'])
incremented_number = number + 1
return render_template('index.html', incremented_number=incremented_number)
else:
return... |
null | Create a Java function to calculate the area of a triangle from its three vertices. | A=(2,3), B=(3,4), C=(4,5). | public static double getTriangleArea(Point A, Point B, Point C) { double area = 0.5 * (A.x * B.y + B.x * C.y + C.x * A.y - B.x * A.y - C.x * B.y - A.x * C.y); return area; } |
null | Write an R script to compute the sum of all the elements of a given list. | list = c(1, 2, 3, 4, 5) | sum <- 0 for(i in list){ sum <- sum + i } print(sum) # Output: 15 |
[EN Wikipedia] Nothing's Real but Love
"Nothing's Real but Love" is the debut single by English singer-songwriter Rebecca Ferguson. The song serves as the lead single from the debut studio album, Heaven, and was released in the United Kingdom on 20 November 2011, having originally been scheduled for release the follow... | null | null | null |
null | Design a program in Python to separate a list of numbers into even and odd numbers. | [2, 3, 5, 6, 8, 9, 10] | def separate_numbers(list):
even_numbers = []
odd_numbers = []
for num in list:
if num % 2 == 0:
even_numbers.append(num)
else:
odd_numbers.append(num)
return even_numbers, odd_numbers
list = [2, 3, 5, 6, 8, 9, 10]
even_numbers, odd_numbers = separate_numbers(lis... |
null | Generate a python program that takes input as a string and prints out each word in the string in reverse order. | This is an example. | # Take input
text = input('Enter a string: ')
# Split string into words
words = text.split(' ')
# Reverse order
words.reverse()
# Print
for word in words:
print(word) |
null | Write a Python program to calculate a value from a given sequence of numbers. The program should calculate the sum of the sequence elements and return the sum of the squares of the odd numbers from the sequence. | sequence = [2, 4, 5, 6, 7] | def calc_sum(sequence):
sum = 0
for num in sequence:
sum += num
return sum
def calc_sum_squares(sequence):
sum = 0
for num in sequence:
if num % 2 == 1:
sum += num * num
return sum
sequence = [2, 4, 5, 6, 7]
total_sum = calc_sum(sequence)
sum_squares = calc_sum_squares(sequence)
print("Total sum:", total... |
null | Use the Python built-in function filter() to find all numbers divisible by 5. | mylist = [10, 21, 32, 45, 56, 77] | list(filter(lambda x: (x % 5 == 0), mylist)) |
null | Write a Python program to filter a list of strings and only return strings with two or more words. | my_list = ["hello", "world", "how", "are", "you", "I am fine"] | my_list = ["hello world", "how are you", "I am fine"]
filtered_list = [i for i in my_list if len(i.split())>1]
print(filtered_list)
# Output: ['hello world', 'how are you', 'I am fine'] |
null | Develop a program to perform edit distance calculation on two strings in Python. | def edit_distance(str1, str2):
matrix = []
for i in range(len(str1) + 1):
matrix.append([0] * (len(str2) + 1))
for i in range(len(str1) + 1):
matrix[i][0] = i
for j in range(len(str2) + 1):
matrix[0][j] = j
for i in range(1, len(str1) + 1):
for j in ... | |
null | Create a C program to print the given matrix in the following elements | int arr[3][3] = {1,2,3,4,5,6,7,8,9}; | #include<stdio.h> int main() { int arr[3][3] = {1,2,3,4,5,6,7,8,9}; int i,j; for(i=0;i<3;i++) { for(j=0;j<3;j++) printf("%d ",arr[i][j]); printf("\n"); } return 0; } |
null | Write a Python program to determine the sum of the elements of an array, after applying a given function to each array element. | def func(x):
return x * x
arr = [1, 2, 3, 4] | def element_wise_sum(func, arr):
sum = 0
for elem in arr:
sum += func(elem)
return sum
sum = element_wise_sum(func, arr) |
null | Given a 2D array, replace every element with the greatest element on its row. | [[6, 2, 9], [3, 8, 7], [1, 4, 5]] | def greatest_element(arr): # loop through elements of 1D array for i in range(len(arr)): max_element = arr[i][0] # loop through elements of 2D array for j in range(len(arr[i])): if arr[i][j] > max_element: max_element = arr[i][j] # replace every element with max_element for j in range(len(arr[i])): arr[i][j] = max_elem... |
null | Create a random number generator in Java that produces a random integer between 1 and 10. | public class RandomNumberGenerator { public static int generateNumber() { Random rand = new Random(); return rand.nextInt(10) + 1; } } | |
null | Generate a loop to find the largest sub-array in a given array with contiguous elements and its sum. | Array: [-2, 6, -3, 5, -2, 3, 4, -2] | """ Generate a loop to find the largest sub-array in a given array with contiguous elements and its sum. """ def largest_subarray_sum(array): best_sum = 0 current_sum = 0 current_start_index = 0 best_start_index = -1 best_end_index = -1 for i in range(len(array)): current_sum += array[i] if current_sum > best_sum: best... |
null | Design a function in Python to test if the given number is a prime or not. | N = 13 | def is_prime(n):
if n <= 1:
return False
for i in range(2, n):
if n % i == 0:
return False
return True
is_prime(13) # True |
null | Generate a python code to classify an array of numbers into a set of categories | Given an array of numbers [3, 8, 15, 7, 20], classify the array into two categories - even and odd. | def even_odd_classification(arr):
evens = []
odds = []
for i in arr:
if i % 2 == 0:
evens.append(i)
else:
odds.append(i)
return evens, odds |
[CS Wikipedia] Houbaření
Houbaření je záliba, která spočívá v chození po lese a hledání a sbírání hub. Někteří houbaři pěstují houby i doma. Češi jsou považováni za nejvášnivější houbaře na světě, alespoň jednou ročně vyrazí na houby přes sedmdesát procent obyvatel České republiky, což nemá ve světě obdoby a což z Čes... | null | null | null |
null | Construct a Python program to predict whether a given patient has cancer or not. | Features of the patient: age = 25, sex = male, BMI = 25, number of children = 0 | import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
# Get the data
data = pd.read_csv('data.csv')
# Create the features and target arrays
X = data.drop(columns=['has_cancer'])
y = data['has_cancer']
# Split into training and ... |
null | Design a structure in Python to store data related to airport schedules. | class FlightSchedule:
def __init__(self):
self.airport_info ={}
def add_flight(self,flight_name,source,destination,departure_time,arrival_time):
self.airport_info[flight_name] = {
'source': source,
'destination': destination,
'departure_time': departure_time,
'arriva... | |
null | Create a webpage with a button to allow the user to log in. | [noinput] | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Login Page</title> </head> <body> <form action="login.php" method="post"> <input type="submit" value="Login" /> </form> </body> </html> |
null | Using Java, write a program to determine if a given word is a palindrome. | word = "racecar" | boolean isPalindrome = true; for (int i = 0; i < word.length()/2; i++ ){ if (word.charAt(i) != word.charAt(word.length()-i-1)){ isPalindrome = false; break; } } |
[HI Wikipedia] हिन्दी संगठन
हिन्दी संगठन या 'हिन्दी स्पीकिंग यूनियन' मॉरीशस की एक प्रमुख हिन्दीसेवी संस्था है। इसकी स्थापना संसद के विधेयक संख्या ३३ के तहत १२ दिसम्बर १९९४ को हुई थी। यह संस्था कला एवं संस्कृति मंत्रालय के सहयोग से अपनी गतिविधियाँ आयोजित करती है। इसका कार्यालय आर्किड टॉवर, पोर्ट लूई में है। हिन्दी विद्... | null | null | null |
null | Create a Python script to calculate the sum of the numbers in a list given as input. | list = [1, 5, 10, 30] | def sum_list(list):
total = 0
for i in list:
total += i
return total
print sum_list(list) |
null | Generate a function for calculating the average of a list of numbers in Python. | Not applicable | def avg_list(lst):
sum = 0
count = 0
for i in lst:
sum += i
count += 1
avg = sum / count
return avg |
null | Identify the correct data type for the value "37.45". | float | |
[CS Wikipedia] Lísek (rozcestník)
Název Lísek má více míst: Lísek, obec v okrese Žďár nad Sázavou Lísek (Postupice), část obce Postupice v okrese Benešov Lísek (hrad), zřícenina Lísek (Hudlice), osada ve východní části obce Hudlice v okrese Beroun, na západním úbočí kopce Lísek Lísek (483 m), kopec východně od Hudlic,... | null | null | null |
null | Napiš Python funkci pro faktoriál. | def factorial(n):
if n < 0:
raise ValueError('n >= 0')
r = 1
for i in range(2, n+1):
r *= i
return r | |
null | Given a list of numbers, find the number which appears the most times in the list. | [2, 3, 4, 2, 3, 2, 3, 2] | The number which appears the most times in the list is 2, which appears 4 times. |
[CS Wikipedia] Všeobecná deklarace lidských práv
Všeobecná deklarace lidských práv je nezávazný dokument, obsahující nejznámější katalog lidských práv. Ve třiceti článcích deklarace jsou vyjmenována základní občanská, politická, kulturní, ekonomická a sociální práva platná pro všechny obyvatele na Zemi. Podle některýc... | null | null | null |
null | Write a JavaScript function to convert an array to a string separated by key-pair value separator such as "|". | const array1 = [1,2,3,4,5]; | function arrayToString(arr, separator="|") { return arr.join(separator); } arrayToString(array1); // returns "1|2|3|4|5" |
null | Create a Python class for a particle whose properties include mass, velocity and temperature. | class Particle():
def __init__(self, mass, velocity, temperature):
self.mass = mass
self.velocity = velocity
self.temperature = temperature | |
null | Develop a greedy algorithm in Python to complete a given optimization task. | def greedy_solution(arr):
arr.sort()
cur_max = arr[0]
result = [cur_max]
for i in range(1, len(arr)):
if arr[i] > cur_max + 1:
cur_max = arr[i]
result.append(cur_max)
return result | |
[DE Wikipedia] Galatas
Galatas (griechisch Γαλατάς) bezeichnet mehrere Orte in Griechenland Galatas (Ziros) Dorf in der Gemeinde Ziros, Region Epirus Galatas (Nafpaktia) Dorf in der Gemeinde Nafpaktia, Region Westgriechenland Galatas (Gortynia) Dorf in der Gemeinde Gortynia, Region Peloponnes Galatas (Nemea) Dorf in d... | null | null | null |
[HI Wikipedia] न्यू इंग्लैंड
न्यू इंग्लैंड () संयुक्त राज्य अमेरिका का एक भौगोलिक क्षेत्र है जिसमें पूर्वोत्तर संयुक्त राज्य के छह राज्य शामिल हैं: मेन, वरमॉण्ट, न्यू हैम्पशायर, मैसाचुसेट्स, रोड आइलैंड और कनेक्टिकट। यह न्यूयॉर्क से पश्चिम और दक्षिण में सीमा रखता है और कनाडाई प्रान्तों न्यू ब्रंसविक और क्यूबेक से क्रमश... | null | null | null |
null | Write an SQL query to get the number of customers per country | Table Name: Customers Columns: Name, Country | SELECT Country, COUNT(*) AS NumberOfCustomers FROM Customers GROUP BY Country; |
null | Given a list of numbers, remove all negative numbers and sort the remaining numbers in ascending order. | numbers = [-5, -1, 2, 0, 4, 5, 9] | def remove_negatives_and_sort(numbers): # filter out negative numbers non_negatives = list(filter(lambda x: x >= 0, numbers)) # sort the non-negative numbers non_negatives.sort() return non_negatives print(remove_negatives_and_sort([-5, -1, 2, 0, 4, 5, 9])) # [0, 2, 4, 5, 9] |
null | Write a function that produces an array of Fibonacci numbers with n numbers. | def fibonacci(n): if n == 0: return [] elif n == 1: return [0] elif n == 2: return [0, 1] elif n > 2: fib_nums = [0, 1] for i in range(2, n): fib_nums.append(fib_nums[i-1] + fib_nums[i-2]) return fib_nums | |
null | Create a Python program to sort a given list of numbers within a range and return the sorted list. | arr = [7, 0, 5, 6, 3, 9]
start = 0
end = 9 | def sort_in_range(arr, start, end):
# create a count array to store the count of each number
count = [0 for i in range(start, end+1)]
output = []
# count the occurance of each number in the array
for num in arr:
count[num] += 1
# append the number to the output array for each occurance... |
null | Generate a function to multiply two integers. | def multiply_ints(x, y): return x * y | |
null | Sort a list of user objects by their age | users = [{'name': 'John', 'age': 10}, {'name': 'Peter', 'age': 20}, {'name': 'Chris', 'age': 15}] | sorted_users = sorted(users, key=lambda k: k['age']) |
null | Explain in detail what is the significance of a local variable in Python | A local variable in Python is a variable that is declared within a function or a class. It is a variable that only exists in the context of that function or class, and cannot be accessed outside the function or class in which it is declared. Local variables are also referred to as "lexical" or "automatic" variables bec... | |
[HI Wikipedia] शूमाँ घोषणा-पत्र
फ्रांस के विदेशमंत्री रॉबर्ट शूमाँ ने कोयला और स्टीम उत्पादन में सहयोग के लिए जर्मनी और फ्रांस के लिए एक योजना घोषित की। कुछ अन्य देशों को भी इसमें शामिल होने का न्यौता दिया गया। शूमाँ योजना इस विचार पर आधारित थी कि शांति के लिए यूरोपीय एकता बहुत ज़रूरी है। रॉबर्ट शूमाँ ने कहा कि उत्पाद... | null | null | null |
null | Write a Python class with methods for printing strings and computing the length of a string. | class MyString:
def __init__(self):
self.string = ""
def set_string(self, string):
self.string = string
def get_string(self):
return self.string
def print_string(self):
print(self.string)
def get_length(self):
string_length = len(self.string)
r... | |
[CS Wikipedia] Celebration (píseň, Kool & the Gang)
„Celebration“ je post-disco/funk/popový singl z roku 1980 od skupiny Kool & the Gang. Skladba pochází z alba Celebrate!. 7. února 1981 se píseň se umístila v Hot 100 na #1 příčce. Dále si vydobyla 1. místo i v jiných Billboard hitparádách, respektive v R&B a Dance že... | null | null | null |
null | Create a Python function to encode an input string using the Caesar Cipher | Not applicable | def caesar_cipher(input_string, shift):
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
output_string = ''
for char in input_string:
if char in alphabet:
char_index = alphabet.find(char)
new_char_index = char_index + shift
output_string += alphabet[new_char_index % len(a... |
[DE Wikipedia] Innokenti Dmitrijewitsch Meltschakow
Innokenti Dmitrijewitsch Meltschakow (; * in Irkutsk; † unbekannt) war ein russischer Architekt und Hochschullehrer. Leben Meltschakow trat 1927 in I. L. Kopylows Kunststudio in Irkutsk ein und verließ es 1930 mit dem Titel Künstler-Techniker. Anschließend ging er na... | null | null | null |
null | Given a list of strings, write a program to return all strings with first character as 'c'. | list_strings = ["cat", "dog", "cow", "duck"] | required_strings = [] for string in list_strings: if string[0] == 'c': required_strings.append(string) # required_strings = ["cat", "cow"] |
null | Implement quick sort in Java. | public static void quickSort(int[] arr, int low, int high) { if (arr == null || arr.length == 0) return; if (low >= high) return; // pick the pivot int middle = low + (high - low) / 2; int pivot = arr[middle]; // make left < pivot and right > pivot int i = low, j = high; while (i <= j) { while (arr[i] < pivot) { i++; }... | |
null | Write a function in Python to check if an element is present in an array. | arr = [1, 2, 3, 5, 7]
element = 4 | arr = [1, 2, 3, 5, 7]
element = 4
def contains(arr, element):
for e in arr:
if e == element:
return True
return False
result = contains(arr, element)
print(result) |
null | Write a Python program to calculate the area of a triangle given 3 sides. | side1=5, side2=8, side3=7 | def area(side1, side2, side3):
# calculate the semi-perimeter
s = (side1 + side2 + side3)/2
# calculate the area
area = (s*(s-side1)*(s-side2)*(s-side3)) ** 0.5
return area |
null | Using the given list of strings, create a function to count and return the number of capital letters in the list. | def count_capital_letters(string_list): count = 0 for string in string_list: for char in string: if char.isupper(): count += 1 return count | |
null | Write a Python class to detect and block malicious requests. | class RequestChecker():
def __init__(self):
pass
def check_request(self, request):
# Your code to check the request
is_malicious = False # If a malicious request is found, set it to True
if is_malicious:
print('Malicious request detected!')
else:... | |
null | Construct an for loop in R for reading in a csv of an dataset. | file_name = "mydata.csv" | d <- read.csv(file_name) for (i in 1:nrow(d)) { # do something with each row of data } |
null | Replace the for-loop in the following Python function with an equivalent while loop. | def count_down(value):
ret = 1
for i in range(value, 0, -1):
ret *= i
return ret | def count_down(value):
ret = 1
while value > 0:
ret *= value
value -= 1
return ret |
null | Write a JavaScript code that prints out even numbers between 0 and 50. | for (let i = 0; i <= 50; i++) { if (i % 2 == 0) { console.log(i); } } | |
[DE Wikipedia] Eisenbahnunfall von Woodville
Bei dem Eisenbahnunfall von Woodville stieß bei Woodville, Indiana, USA, am 12. November 1906 ein Güterzug frontal mit einem in der Gegenrichtung verkehrenden Personenzug zusammen. 43 Menschen starben. Ausgangslage Die Zugsicherung sollte auf der eingleisigen Strecke der Ba... | null | null | null |
null | Create a Python script to reverse each word in a sentence. | Sentence = "This is a test" | # Create a empty list to store the reversed sentences
reversed_sentences = []
# Get the list of words from the given sentence
words = sentence.split(' ')
# Reverse each word
for word in words:
reversed_word = word[::-1]
reversed_sentences.append(reversed_word)
# Print the reversed sentence
reversed_sentence = '... |
null | Edit the given HTML code to create a paragraph element. | <div>Hello World!</div> | <div><p>Hello World!</p></div> |
null | Create a function to round a number to the nearest integer. | def round_number(x): return round(x) | |
null | Design a data structure to store a list of names of the student with their respective grades in a class. | Student names and grades [ ['John', 90], ['Tom', 80], ['Jill', 95], ['Stacy', 75] ] | class StudentGrades: def __init__(self, names, grades): self.names = names self.grades = grades def add_entry(self, name, grade): self.names.append(name) self.grades.append(grade) def get_grade(self, name): for i in range(len(self.names)): if self.names[i] == name: return self.grades[i] |
null | Automate the testing of a Python Flask application by writing a script that will run unit tests on the models. | Not applicable | import unittest
from flask_testing import TestCase
from app import db, Task
class TestModel(TestCase):
def create_app(self):
return app
def setUp(self):
db.create_all()
self.task = Task(description='Description')
db.session.add(self.task)
db.session.commit()
def tearDown(self):
db.session.remove()
db.drop_... |
null | Create a Python function to format a string with the proper case and punctuation | string="hello, world" | def format_string(string):
"""Function to format a string with the proper case and punctuation"""
return string.lower().capitalize() + "." |
null | Create a Q-Learning algorithm in Python to play the game '2048'. | import numpy as np
import random
class QLearner:
def __init__(self, alpha=0.2, gamma=0.9):
self.alpha = alpha
self.gamma = gamma
self.Q = dict()
def get_Q(self, state, action):
"""
Return Q-value for a given state and action.
"""
return self.Q.get((... | |
null | Create a Python class called "Friend" with fields "name", "age" and "hobbies". | Not applicable | class Friend:
def __init__(self, name, age, hobbies):
self.name = name
self.age = age
self.hobbies = hobbies
def getName(self):
return self.name
def getAge(self):
return self.age
def getHobbies(self):
return self.hobbies |
null | Rewrite the following code snippet from Python to JavaScript, taking into account any changes in syntax or function calls.
m = "Hello, World!"
print(m) | let m = 'Hello, World!';
console.log(m); | |
[EN Wikipedia] Andrey Markov
Andrey Andreyevich Markov (14 June 1856 – 20 July 1922) was a Russian mathematician best known for his work on stochastic processes. A primary subject of his research later became known as the Markov chain. He was also a strong, close to master-level chess player. Markov and his younger br... | null | null | null |
null | Write a query in SQL to select all the rows from table Books. | SELECT * FROM Books; | |
[DE Wikipedia] Franz August Müller (Fechter)
Franz August Müller (* vor 1920; † nach 1932) war ein deutscher Fechter, der mit dem Fecht-Club Hermannia Frankfurt mehrfacher deutscher Mannschaftsmeister in allen drei Disziplinen (Degen, Florett und Säbel) wurde. Müller gewann bei den deutschen Einzelmeisterschaften 1920... | null | null | null |
null | Create a program in Python to read input from the user and respond with a randomly generated quote. | Not applicable | import random
quotes = [
"It's not who you are that holds you back, it's who you think you're not.",
"You don't have to be great to start, but you have to start to be great.",
"It's not what happens to you, but how you react to it that matters.",
"It does not matter how slowly you go, as long as you do not stop."
... |
[DE Wikipedia] Sant Cebrià de Vallalta
Sant Cebrià de Vallalta ist eine katalanische Gemeinde in der Provinz Barcelona im Nordosten Spaniens. Sie liegt in der Comarca Maresme. Sehenswürdigkeiten Kirche Sant Cebrià de Vallalta Einzelnachweise Weblinks Information der Generalitat de Catalunya zu Sant Cebrià de Vallalta ... | null | null | null |
[DE Wikipedia] Richtlinie 2002/46/EG
Die Richtlinie 2002/46/EG ist eine Europäische Richtlinie, die harmonisierte Bestimmungen für Nahrungsergänzungsmittel, die als Lebensmittel in der Europäischen Union in Verkehr gebracht werden, enthält. Sie soll sicherstellen, dass Verbraucher bei Nahrungsergänzungsmitteln keine i... | null | null | null |
[EN Wikipedia] Assassin (Cain novel)
Assassin is the third novel of the Samuel Carver series by English thriller writer, Tom Cain, released on 2 July 2009 through Bantam Press. Plot This novel takes place twelve years after the previous Samuel Carver novel, The Survivor, with Carver having spent the intervening years ... | null | null | null |
null | Replace the placeholder with a for loop for iterating over the numbers from 1 to n and printing them. | for i in range(n): # TODO | for i in range(1, n+1): print(i) |
[EN Wikipedia] Shin River (New Zealand)
The Shin River is a river in New Zealand's Marlborough Region. It flows north from its sources in the Inland Kaikoura Range to reach the Hodder River, which is part of the Awatere River system, located southwest of Seddon, New Zealand. See also List of rivers of New Zealand Refe... | null | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.