text stringlengths 141 2.89k ⌀ | instruction stringlengths 19 1.5k ⌀ | input stringlengths 0 800 ⌀ | output stringlengths 1 2.5k ⌀ |
|---|---|---|---|
null | This code is an OTA firmware update script for ESP8226 implementation of the Homie MQTT IoT convention. To use it, you need to run the main function with the following arguments: broker-host, broker-port, broker-username, broker-password, base-topic, device-id, and firmware. The firmware argument should be the path to ... | #!/usr/bin/env python
from __future__ import division, print_function
import paho.mqtt.client as mqtt
import base64, sys, math
from hashlib import md5
# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
if rc != 0:
print("Connection ... | |
null | Extract the first 2 elements from a given array. | arr = [1, 2, 3, 4, 5] | def extract_first_two(arr): return arr[:2] arr = [1, 2, 3, 4, 5] result = extract_first_two(arr) print (result) # Output: [1, 2] |
[CS Wikipedia] Laminární proudění
Laminární proudění je takové proudění vazké kapaliny, při kterém jsou proudnice rovnoběžné a nemísí se. Částice kapaliny se pohybují vedle sebe jakoby ve vrstvách – „destičkách“ (destička = lat. lamina), které se vzájemně nepromíchávají. Odtud také laminární neboli vrstevnaté proudění... | null | null | null |
null | Convert the following chess board into a 2D array in JavaScript. | +---+ |BR | |BK | | BB| |BR | +---+ | let chessBoard = [["BR", "BK", "BB", "BR"]]; |
null | Write an algorithm to detect a cycle linked list in Python. | def detect_cycle(head):
"""Detects whether a linked list contains a cycle.
Args:
head (ListNode): The head node of the linked list.
Returns:
bool: True if there is a cycle, and False if there isn't.
"""
slow = head
fast = head
while fast and fast.next:
# move slow ... | |
null | Write a Java program to remove comments from the Java program. | public class HelloWorld { /* This is a multiline comment. */ public static void main(String[] args) { System.out.println("Hello World!"); // This is a single line comment. } } | public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } |
null | Create a SQL query to display the total number of sales in each year. | Table Name: "Sales" Table Columns: "year", "total_sales" | SELECT year, SUM(total_sales) FROM Sales GROUP BY year; |
null | Reverse a linked list. | def reverseList(node): prev = None while (node != None): next = node.next node.next = prev prev = node node = next return prev | |
[CS Wikipedia] Vaška
Vaška () je řeka v Komiské republice a v Archangelské oblasti v Rusku. Je dlouhá 605 km. Povodí řeky je 21 000 km². Nazývá se také Važka (). Průběh toku Pramení v mokřadech na rozvodí Mezeně a Severní Dviny. Na svém toku vytváří mnoho zákrut a mrtvých ramen. V jejím povodí je přibližně 900 jezer. ... | null | null | null |
[HI Wikipedia] शॉम्पनी
अंडमान निकोबार की जनजातियों में शॉम्पनी (लगभग 200) एक विलुप्त होती हुई प्रजाति है। ये मंगोल नस्ल की है जबकि अंडमान और निकोबार की बाक़ी सभी जनजातियाँ नीग्रोईड यानी अफ्रीकियों जैसी हैं। अण्डमान और निकोबार की जनजातियां | null | null | null |
null | Check this code and add an if statement to print out “even” if the number is divisible by 2 and “odd” if not. | for n in range (1,10): print(n) | for n in range (1, 10): if n % 2 == 0: print(n, "even") else: print(n, "odd") |
null | Explain how a support vector machine works. | A Support Vector Machine (SVM) is a supervised learning algorithm that can be used for binary classification, regression, or outlier detection. SVMs use a hyperplane to separate data points into two categories, each represented by a different class. The hyperplane divides data points into classes by minimizing the dist... | |
null | Create a Java program which takes a year as input and prints whether it is a leap year or not. | year = 2020 | public class LeapYear { public static void main(String args[]) { int year = 2020; if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) System.out.println("The year is a leap year."); else System.out.println("The year is not a leap year."); } } |
null | Create a Python function that takes a string and rotates the characters in the string by a specified integer. | "Hello", 3 | def rotateString(s, n):
output = ""
for char in s:
output += chr(ord(char) + n)
return output
result = rotateString("Hello", 3)
print(result) |
null | Insert a breakpoint just before the return statement. | def calculate_the_total(fruit_list): total = 0 for item in fruit_list: total += item return total | def calculate_the_total(fruit_list): total = 0 for item in fruit_list: total += item import pdb; pdb.set_trace() return total |
null | Enhance the following code to find the average of all the even numbers in the array: | my_array = [1,2,3,4,5,6] | even_numbers = [] for number in my_array: if number % 2 == 0: even_numbers.append(number) average = sum(even_numbers) / len(even_numbers) print(average) |
null | Create a list comprehension to generate a list of all the words in the sentence "Python is amazing". | words = [word for word in "Python is amazing".split(' ')] | |
[HI Wikipedia] अंग लिपि
लगभग 2500 बर्ष पूर्व लिखे गये प्रसिद्ध प्राचीन बौद्ध ग्रंथ "ललित विस्तर" में वर्णित64 लिपियों में "अंग लिपि" का स्थान चौथा है। लिपि | null | null | null |
null | Automate the process of building a Python program that takes in the names of two people as input, and outputs the age difference between them. | John Doe, Jane Doe | # Program to compute age difference between two persons
# Input
name1 = input('Enter name of first person: ')
name2 = input('Enter name of second person: ')
# Compute age difference
ages = {
'John Doe': 35,
'Jane Doe': 27
}
diff = abs(ages[name1] - ages[name2])
# Output
print(f'The age difference between {name1} ... |
[DE Wikipedia] Pariacaca
Der Nevado Pariacaca ist ein Berg in der Cordillera Huarochirí (auch „Pariacaca-Gebirgskette“ genannt) in der Westkordillere der peruanischen Anden. Der vergletscherte Berg besitzt zwei Gipfel: den Nordgipfel mit einer Höhe von sowie den Südgipfel mit . Der Nevado Pariacaca bildet die höchste ... | null | null | null |
null | Create a Python class for a basic calculator with an add and subtract function. | Not applicable | class Calculator:
def __init__(self):
self.values = []
def add(self, x, y):
self.values.append(x + y)
def subtract(self, x, y):
self.values.append(x - y)
calc = Calculator()
calc.add(2, 3)
calc.subtract(3, 4)
print(calc.values[-1]) |
null | Create a function to create a NxN matrix in Python with all elements equal to a given number. | N=5, num=7 | def mat_gen(N, num):
matrix = [[num for col in range(N)] for row in range(N)]
return matrix
mat_gen(5, 7) |
null | Create a Python program that takes an email message as input and prints the sender's email address. | Email Message:
From: "John Doe" <john.doe@example.com>
To: "Jane Doe" <jane.doe@example.com>
Subject: Example Email | import re
email_message = """
From: "John Doe" <john.doe@example.com>
To: "Jane Doe" <jane.doe@example.com>
Subject: Example Email
"""
sender_email = re.findall(r'From: .+?<(.+?)>', email_message)
print('Sender\'s email address:', sender_email[0]) |
null | Calculate the sum of the first 10 Fibonacci numbers in Java. | class Fibonacci { static int fib(int n) { if (n <= 1) return n; return fib(n-1) + fib(n-2); } public static void main (String args[]) { int num = 10, sum = 0; for (int i = 1; i <= num; i++) { sum += fib(i); } System.out.println(sum); } } | |
null | Edit the following Python code to improve its readability. | def calctrade():
c=50
b=50
while (c > 0 and b > 0):
c–
b-=2
return c + b | def calculate_trade():
coal = 50
barley = 50
while coal > 0 and barley > 0:
coal -= 1
barley -= 2
return coal + barley |
null | Write a SQL query which will select column names from a certain table. | SELECT column_name FROM table_name; | |
null | Explain the functional programming paradigm. | Functional Programming is a programming paradigm that emphasizes the use of functions, or predefined sequences of commands, to produce desired results. This paradigm tries to avoid state and mutable data, and instead use higher-order functions to pass functions as arguments. This makes it easier to understand, debug, a... | |
null | Write a Python function to filter strings using a filter function as a parameter. | def filter_strings(strings, filter_function):
filtered = []
for string in strings:
if filter_function(string):
filtered.append(string)
return filtered | |
null | Complete the function below to make a list of n numbers and return the result. | n = 5 | def create_list(n): result = [] for i in range(0,n): result.append(i) return result |
null | Create a class named Person with two properties: name and age. | class Person { private: string name; int age; public: Person(string name, int age) { this->name = name; this->age = age; } void setName(string name) { this->name = name; } void setAge(int age) { this->age = age; } string getName() { return name; } int getAge() { return age; } }; | |
null | Fill in the blank to generate a SHA-256 hash in JavaScript: | const crypto = require('crypto'); const hash = crypto.createHash('sha256'); | |
[HI Wikipedia] देवघर
देवघर, () भारत के झारखण्ड राज्य का एक शहर है। यह देवघर जिले का मुख्यालय तथा हिन्दुओं का प्रसिद्ध तीर्थस्थल है। इसे 'बाबाधाम' नाम से भी जाना जाता है| यहाँ भगवान शिव का एक अत्यन्त प्राचीन मन्दिर स्थित है। हर सावन में यहाँ लाखों शिव भक्तों की भीड़ उमड़ती है। यहाँ भारत के विभिन्न भागों से तीर्थयात्री ... | null | null | null |
[CS Wikipedia] Peñaflor (Chile)
Město Peñaflor se nachází v Chile v Metropolitním regionu v provincii Talagante. Ve městě žije obyvatel. Ve městě sídlí také závod firmy Baťa, který zde byl otevřen roku 1939. Odkazy Reference Externí odkazy Města v Chile Sídla v Santiagu (metropolitní region) Baťovské satelity | null | null | null |
null | Create a program which takes an integer input n and prints its factorial. | n = 5 | def factorial(n): fact = 1 for i in range(1, n+1): fact = fact * i return fact print(factorial(n)) |
null | Can you build a Python program which calculates the sum of digits of an inputted number? | def sumDigits(num):
sum = 0
while(num):
sum += num % 10
num = num//10
return sum
# main function
num = 12345
print("Sum of digits of specified number is: ",
sumDigits(num)) | |
null | Create a web scraper using Python and Beautiful Soup that collects data from a certain web page and stores it into a database. | Not applicable | import requests
from bs4 import BeautifulSoup
import sqlite3
# Connect to the database
conn = sqlite3.connect('data.db')
# Scrape the webpage
r = requests.get("http://example.com")
soup = BeautifulSoup(r.content, 'html.parser')
# Extract the necessary data
data = []
for tag in soup.find_all('div'):
data.append(tag... |
null | Generate a Bash script that runs a Python program. The Python program should receive a string as input, print its size, and then sort the string in alphabetical order. | Sample string: "Hello, world" | #!/bin/bash
# Script to run Python program
input_string="Hello, world"
python <<END
input_string="$input_string"
print("Input string:", input_string)
print("Size of string:", len(input_string))
print("Sorted string:", ''.join(sorted(input_string)))
END |
null | Given 2 integers, write a Python program to check whether the numbers are divisible. | Number1: 5
Number2: 10 | def is_divisible(num1, num2):
if num1 % num2 == 0:
return True
else:
return False
check_result = is_divisible(5, 10)
if check_result == True:
print("The numbers are divisible")
else:
print("The numbers are not divisible") |
null | Create a Python code to output the following text: | print("Hello, World!") | |
null | Develop a Python program that creates a random password of length 8 characters. | import string import random length = 8 all_characters = string.ascii_letters + string.digits + string.punctuation password = "".join(random.choice(all_characters) for i in range(length)) print(password) | |
null | Develop a Python program to detect a loop in a linked list. | class Node:
def __init__(self, data):
self.data = data
self.next = None
def detect_loop(head):
slow_ptr = head
fast_ptr = head
#check if the linked list is empty
if head is None:
return False
#iterate over the list
while fast_ptr is not None and fast_ptr.next is no... | |
[EN Wikipedia] Abstract (law)
In law, an abstract is a brief statement that contains the most important points of a long legal document or of several related legal papers. Types of legislation The abstract of title, used in real estate transactions, is the more common form of abstract. An abstract of title lists all t... | null | null | null |
[DE Wikipedia] James Morgan Walsh
James Morgan Walsh (* 23. Februar 1897 in Geelong, Victoria; † 29. August 1952 in Weston-super-Mare, Somerset) war ein australischer Schriftsteller. Leben Walsh war ein Sohn des Geschäftsmanns Thomas Patrick Walsh und dessen Ehefrau Kate Morgan. Nach dem Besuch der Grundschule in sein... | null | null | null |
[HI Wikipedia] रक्षा अनुसंधान एवं विकास संगठन
रक्षा अनुसंधान एवं विकास संगठन (अंग्रेज़ी:DRDO, डिफेंस रिसर्च एण्ड डेवलपमेंट ऑर्गैनाइज़ेशन) भारत की रक्षा से जुड़े अनुसंधान कार्यों के लिये देश की अग्रणी संस्था है। यह संगठन भारतीय रक्षा मंत्रालय की एक आनुषांगिक ईकाई के रूप में काम करता है। इस संस्थान की स्थापना १९५८ में भ... | null | null | null |
null | Using a stack, create a python program to convert a given infix expression to a corresponding postfix expression. | Expression: 3*(2+5)/3 | def convert_to_postfix(expression):
# Create a stack
stack = []
# Output string
postfix = ""
# Operators
operators = {"+", "-", "*", "/"}
# Loop through the expression
for char in expression:
if char not in operators:
# If the character is a number, add it to the outp... |
null | Suggest a solution for the following prompt. | Write a Python script to generate the Fibonacci sequence up until n number of terms. | # Python 3 program to generate Fibonacci sequence
def Fibonacci(n):
a = 0
b = 1
if n < 0:
print("Incorrect input")
elif n == 0:
return a
elif n == 1:
return b
else:
for i in range(2,n):
c = a + b
a = b
b = c
... |
null | Delete the forth row from the following table using an SQL query. | Table: id | name ------------------- 1 | John 2 | Jane 3 | Jacob 4 | Jill | DELETE FROM Table WHERE id = 4; |
null | Write a function that takes a list and an item as parameters and appends the item to the list. | def append_item(my_list, item): return my_list.append(item) | |
null | Create a for loop for printing all the alphabets in the lowercase. | for letter in range(97, 123): print(chr(letter)) | |
[EN Wikipedia] Aubrey Kachingwe
Aubrey Kachingwe (born 1926) is a Malawian novelist and short-story writer. He was educated in Malawi and Tanzania. He is "famed for being the first Malawian writer to publish with the prestigious African Writers Series (arguably the most significant publisher of African Literature in E... | null | null | null |
null | Write a function to calculate the triangular number of a given number n. | def getTriangularNumber(n): return int(n * (n + 1) / 2) | |
[HI Wikipedia] गुवाहाटी मेट्रो
गुवाहाटी मेट्रो, असम के गुवाहाटी महानगर के लिए योजनाबद्ध त्वरित यातायात परियोजना है। इस प्रणाली को ३ गलियारों में विभाजित किया गया है, जिसकी कुल लंबाई ४४.२ किलोमीटर है। इतिहास ११ जनवरी २०१३ को असम राज्य के मुख्यमंत्री तरुण गोगोई कि गुवाहाटी विकास विभाग एवं गुवाहाटी महानगर विकास प्राधिकरण... | null | null | null |
null | Create a function to decrypt an encrypted string. | def decrypt(enc_string): s = 0 decrypted = '' for i in range(len(enc_string)): s += ord(enc_string[i]) decrypted += chr(s) return decrypted | |
null | Create a class in Python that simulates a student's grades in a course. | class Student:
def __init__(self, course_name, grades):
self.course_name = course_name
self.grades = grades
def get_grade(self):
return sum(self.grades) / len(self.grades) | |
[HI Wikipedia] सप्ताह के दिन
सप्ताह के दिन एक सप्ताह या हफ़्ते में सात दिन होते हैं। हिन्दी में ये निम्न नामों से पुकारे जाते हैं। रविवार अथवा इतवार सोमवार मंगलवार बुधवार गुरुवार अथवा बृहस्पतिवार अथवा वीरवार शुक्रवार शनिवार अथवा शनिचर सप्ताह के दिन सामान्यत: एक माह में चार सप्ताह होते हैं और एक सप्ताह में सात दिन होते... | null | null | null |
[EN Wikipedia] Trichostegia
Trichostegia may refer to: Trichostegia (caddisfly), a caddisfly genus in the family Phryganeidae Trichostegia, a synonym of the plant genus Asteridea. | null | null | null |
null | Write JavaScript code for a for loop with condition that iterates 8 times. | for (let i = 0; i < 8; i++) { // code to be executed } | |
null | Generate the syntax tree for a given Python expression. | expression = "(A + B) * (C + D)" | import ast
tree = ast.parse(expression) |
null | Design an object-oriented class in Python to represent a person's contact information | Not applicable | class Contact:
def __init__(self, name, phone, email):
self.name = name
self.phone = phone
self.email = email
def get_name(self):
return self.name
def set_name(self, name):
self.name = name
def get_phone_number(self):
return self.phone
... |
[EN Wikipedia] Virtual Library of Musicology
The Virtual Library of Musicology or ViFaMusik () was funded by the German Research Foundation (Deutsche Forschungsgemeinschaft) to provide sources and materials for music and musicology. The project was active from July 2005 to March 2020 at the Bavarian State Library, in ... | null | null | null |
null | Create a fragment of HTML that displays a button which redirects the user to a given URL. | URL = "http://example.com" | <a href="http://example.com"><button>Go to example.com</button></a> |
null | Write a function in C++ that takes in a string of text and removes all the punctuation from the string. | #include <string> #include <cctype> string remove_punctuation(string s) { string str; for (char c : s) { if (ispunct(c) == false) str.push_back(c); } return str; } | |
null | Come up with a python code to find the mean of a list of numbers. | nums = [78, 79, 79, 79, 79, 80] | total = 0 for num in nums: total += num mean = total/len(nums) print(mean) |
null | Design an algorithm in Python that can print all the prime numbers from 1 to a given number. | def print_prime_numbers(num):
for n in range(2, num+1):
if n == 2 or n ==3 :
print(n, end="")
continue
for i in range(2, n):
if n % i == 0:
break
else:
print(n, end="") | |
null | In python, write a function that takes in two numbers and returns the sum of their digits. | def sum_digits(a,b):
#convert each number to string
a = str(a)
b = str(b)
#initialize sum
sum = 0
for i in range(len(a)):
sum += int(a[i])
for i in range(len(b)):
sum += int(b[i])
#return sum
return sum | |
[HI Wikipedia] युवराज सिंह
युवराज सिंह (युवी) भारत के क्रिकेट खिलाड़ी हैं। उन्होंने 20-20 विश्व कप 2007 में इंग्लैंड के खिलाफ एक ओवर की 6 गेंदों में 6 छक्के मार कर विश्व रिकॉर्ड बनाया था। इसके साथ ही 20-20 में 12 गेंदों में अर्धशतक बनाने का विश्व रिकॉर्ड भी उनके नाम है। युवराज सिंह को २०११ क्रिकेट विश्व कप में अहम भूम... | null | null | null |
[HI Wikipedia] बीकानेर
'> बीकानेर''' [[राजस्थान] एक बड़ा शहर है बीकानेर का पुराना नाम जांगल देश था। यांहा स्थानीय आदिवासी भील राजाओं का शासन था बिका नामक राजपूत सरदार ने स्थानीय आदिवासी भील राजा को मारकर इस नगर का नामकरण उन्हीं के नाम पर बीकानेर किया । बीकानेर राज्य महाभारत काल में जांगल देश था<ref></ref> बीकानेर की भ... | null | null | null |
null | Write a Python code to find all the prime numbers below a given number. | def get_primes(n): primes = [] for num in range(2, n+1): is_prime = True for div in range(2, n): if (num % div == 0): is_prime = False if is_prime: primes.append(num) return primes | |
[CS Wikipedia] David Zayas
David Zayas (* 15. srpna 1962) je portorický herec. Jeho nejznámější role jsou Angel Batista v seriálu Dexter a Enrique Morales v seriálu Oz. Životopis Narodil se v Portoriku. Byl vychováván ve čtvrti Bronx v New Yorku. Kariéra Poté, co sloužil u leteckých sil Spojených států, přidal se k ne... | null | null | null |
[DE Wikipedia] Liste der Lieder von Hilary Duff
Dies ist eine Liste der aufgenommenen und veröffentlichten Lieder der US-amerikanischen Popsängerin Hilary Duff. Die Titel sind alphabetisch sortiert. Sie gibt Auskunft über die Urheber und auf welchem Tonträger die Komposition erstmals zu finden ist. Eigenkompositionen ... | null | null | null |
null | Using Java, write a program that calculates the average of 5 numbers entered by the user. | 2, 4, 6, 8, 10 | import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] numList = new int[5]; int sum = 0; for(int i=0;i<numList.length;i++){ System.out.println("Enter number "+(i+1)); numList[i] = sc.nextInt(); sum += numList[i]; } double avg = (double)sum/numL... |
null | Create a Python script to send an email. | import smtplib
def send_email(sender, recipient, subject, message):
# set up the audience and message
message = """\
From: %s
To: %s
Subject: %s
%s
""" % (sender, recipient, subject, message)
# set up the SMTP connection and send the message
session = smtplib.SMTP('smtp.example.com', 25)
session... | |
[DE Wikipedia] Kriváň
Der Berg Kriváň (deutsch Kriwan, Krummhorn oder Ochsenhorn, polnisch Krywań, ungarisch Kriván) befindet sich im Tatra-Nationalpark (Gebirge Hohe Tatra) und ist ein inoffizielles Nationalsymbol der Slowakei. Mit seiner Höhe von gehört der Kriváň zu den höchsten Erhebungen in der Slowakei und in de... | null | null | null |
null | Write an HTML code to produce an ordered list with the following numbers: 9, 15, 3, 4. | <ol> <li>9</li> <li>15</li> <li>3</li> <li>4</li> </ol> | |
[DE Wikipedia] Nicolaus Rüdinger
Nicolaus Rüdinger (* ca. 1530 in Schefflenz; † 1581 in Wertheim) war ein deutscher neulateinischer Dichter sowie gräflicher Gymnasialrektor und Rentmeister in Wertheim. Leben und Werk Der auch als Nicolaus Rüdiger und Nicolaus Pisovernas bekannte Humanist wurde um 1530 im kurpfälzisch ... | null | null | null |
null | Write a script in Python to generate a histogram of a given data set. | data = [3, 5, 4, 6, 7, 8, 9, 3, 8, 5] | import matplotlib.pyplot as plt
plt.hist(data, 10)
plt.title("Frequency Histogram")
plt.xlabel("Values")
plt.ylabel("Frequency")
plt.show() |
[DE Wikipedia] Dreisbach (Wiehl)
Dreisbach im Oberbergischen Kreis ist eine von 51 Ortschaften der Stadt Wiehl im Regierungsbezirk Köln in Nordrhein-Westfalen. Lage und Beschreibung Der Ort liegt rund vier km östlich des Zentrums von Wiehl. Dreisbach liegt zwischen den Dörfern Drespe (Reichshof) im Norden und Büttingh... | null | null | null |
null | Develop a Python function that will compute the Fibonacci sequence up to n. | def fibonacci(n):
a, b = 0, 1
for i in range(0, n):
a, b = b, a + b
return a | |
null | Create a program in Python to print the sum of all the multiples of 3 and 5 below 1000. | sum = 0
for i in range(1000):
if (i % 3 == 0 or i % 5 == 0):
sum = sum + i
print(sum) | |
null | Write a Python program to calculate the hypotenuse of a right-angled triangle. | a = 5, b = 12 | import math
# calculate the hypotenuse
def calc_hypotenuse(a, b):
hyp = math.sqrt(a**2 + b**2)
print("The length of the hypotenuse is", hyp)
# input lengths of triangle sides
a = 5
b = 12
# call the function
calc_hypotenuse(a, b) |
null | Write a Python program to get all the information associated with an IPv4 address. | IPv4 address = "8.8.8.8" | import socket
ip = "8.8.8.8"
address_info = socket.getaddrinfo(ip, None)
for info in address_info:
print("IP version :", info[0])
print("IP address as string:", info[4][0])
print("IP address as tuple:", info[4])
print("IP protocol:", info[6]) |
null | Implement a stack data structure in Java. | // Stack class class Stack { static final int MAX = 1000; int top; int a[] = new int[MAX]; // Maximum size of Stack boolean isEmpty() { return (top < 0); } Stack() { top = -1; } boolean push(int x) { if (top >= (MAX-1)) { System.out.println("Stack Overflow"); return false; } else { a[++top] = x; System.out.println(x + ... | |
null | Using HTML and CSS, design a landing page for a blog website. | <!DOCTYPE html> <html> <head> <title>My Blog</title> <style> .container{ width:850px; height: 850px; background-color: #F5F5FF; margin:auto; padding: 20px; box-shadow: 0px 0px 7px 1px rgba(0,0,0,0.3); } .header{ background-color: #323B45; font-size: 48px; font-weight: bold; color: #FFF; padding-left: 20px; padding-top:... | |
null | Rewrite the following Python code using vectorization techniques to reduce the computation time. | squares = []
for x in range(100):
squares.append(x * x) | squares = [x * x for x in range(100)] # vectorized code equivalent to the for loop, which will be faster |
[HI Wikipedia] संघट्ट प्राचल
संघात प्राचल () (इम्पेक्ट पैरामीटर) उस लम्बवत दूरी को कहा जाता है जो प्रक्षेप्य पर लगने वाले क्षेत्र के केन्द्र बिन्दु व प्रक्षेप्य के पथ के मध्य होती है। (चित्र देखें)। यह बहुधा नाभिकीय भौतिकी (रदरफोर्ड प्रकीर्णन देखें) व चिरसम्मत यांत्रिकी में काम मे लिया जाता है। संघात प्राचल का प्रकीर्... | null | null | null |
null | Determine the number of ints in a list. | [2, 5, 7, 3, 8] | def count_int(arr): count = 0 for n in arr: if type(n) == int: count +=1 return count |
null | Construct a SQL query to find the total salary spending of an organization by employees in the month of June. | SELECT SUM(salary) AS TotalSalarySpending FROM Empolyees WHERE MONTH(date) = 6; | |
null | Create a program that reads a list of integers and returns the highest prime number in the list. | def get_highest_prime(numbers): highest_prime = 0 for num in numbers: for i in range(2, num): if (num % i == 0): break else: highest_prime = max(highest_prime, num) return highest_prime | |
null | Write a Python program to print the multiplication table for a given number. | Number: 8 | def printMultiplicationTable(num):
for i in range(1, 11):
print("{} x {} = {}".format(num, i, num * i))
printMultiplicationTable(8)
# Output:
# 8 x 1 = 8
# 8 x 2 = 16
# 8 x 3 = 24
# 8 x 4 = 32
# 8 x 5 = 40
# 8 x 6 = 48
# 8 x 7 = 56
# 8 x 8 = 64
# 8 x 9 = 72
# 8 x 10 = 80 |
null | Write a Python function to generate a random number between 1 and 5, given two numbers X and Y. | 4, 8 | import random
def generate_random_number(x, y):
start = min(x, y)
end = max(x, y)
return random.randint(start, end)
result = generate_random_number(4, 8)
print(result) |
[CS Wikipedia] Anna Ticho
Anna Ticho (; 27. října 1894 Brno – 1. března 1980 Jeruzalém) byla izraelská umělkyně, známá svými kresbami Jeruzaléma a jeho okolí. Život Narodila se do židovské rodiny v Brně, kde prožila své rané dětství. Posléze se s rodinou přestěhovala do Vídně, kde v patnácti letech začala studovat mal... | null | null | null |
null | Create a code to read a textfile line by line and print out the lines that have the word "Python". | with open('textfile.txt') as f: for line in f: if 'Python' in line: print(line) | |
null | Design an algorithm to find out the top 5 characters with the highest occurrence from a string in Python. | This is a test sentence to use for the example. | from collections import Counter
def top_characters(string):
counter = Counter(string).most_common(5)
return counter
string = "This is a test sentence to use for the example."
print(top_characters(string))
# Output: [('e', 5), ('s', 4), ('t', 4), ('o', 3), ('i', 3)] |
null | Create a function to get the root of a quadratic equation | 1, 4, 4 | def get_roots_of_quad_eqn(a, b, c): # compute discriminant d = (b**2) - (4 * a * c) # compute roots root1 = (-b + math.sqrt(d)) / (2 * a) root2 = (-b - math.sqrt(d)) / (2 * a) # return the roots return root1, root2 if __name__ == '__main__': a, b, c = 1, 4, 4 print(get_roots_of_quad_eqn(a, b, c)) |
null | Write an algorithm that finds the longest palindromic substring of a given input string. | "forgeeksskeegfor" | // Algorithm to find the longest palindromic substring int longestPalindromicSubstr(char* str) { // Variables to store the start and the end of the palindromic substring int maxLen = 1; int start = 0; int len = strlen(str); // Table to store boolean value at the index // dp[i][j] stores whether the substring str[i..j] ... |
null | Build a python program to multiply two matrices. | Matrix A 2x3
1 2 3
4 5 6
Matrix B 3x2
7 8
9 10
11 12 | def multiply(A, B):
rows_A = len(A)
cols_A = len(A[0])
rows_B = len(B)
cols_B = len(B[0])
if cols_A != rows_B:
# Check matrix dimensions
print("Cannot multiply the two matrices. Incorrect dimensions.")
return
result = [[0 for row in ra... |
null | Write a command line script in Python to print the current day's date. | import datetime
datetime_object = datetime.datetime.now()
print(datetime_object.strftime("%A, %B %d, %Y")) | |
null | Generate a Python program to extract the domain name from a given URL. | url = "https://www.google.com" | import re
def extract_domain_name(url):
pattern = r"([a-z0-9][a-z0-9\-]*?\.(com|org|net|edu|co))(\/|$)"
result = re.search(pattern, url)
return result[1]
print(extract_domain_name(url)) |
null | Convert the following Python code to equivalent JavaScript code. | def add_two_numbers(a, b):
return a + b | function add_two_numbers(a, b) {
return a + b;
} |
null | Produce a SELECT query in PostgreSQL to search for all existing entries with a specified ID. | Property ID: 15 | SELECT * FROM TableName WHERE PropertyID='15'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.