text stringlengths 141 2.89k ⌀ | instruction stringlengths 19 1.5k ⌀ | input stringlengths 0 800 ⌀ | output stringlengths 1 2.5k ⌀ |
|---|---|---|---|
null | Format the below Epoch time (in milliseconds) to a date format in PHP. | Time: 1574395883358 | echo date("Y-m-d H:i:s", 1574395883358/1000); // Output: 2019-11-23 23:54:43 |
null | Write a Java function to classify a given set of numbers into even and odd. | public static void classifyNumber(int[] numbers) { for (int num : numbers) { if (num % 2 == 0) { System.out.println(num + " is even"); } else { System.out.println(num + " is odd"); } } } | |
[HI Wikipedia] केशिराज
केशिराज (कन्नड: ಕೇಶಿರಾಜ) तेरहवीं शती के कन्नड वैयाकरण एवं कवि थे। उन्होने 'शब्दमणिदर्पण' नामक प्रसिद्ध कन्नड व्याकरण ग्रन्थ की रचना की थी। इस कार्य के कारण वे कन्नड व्याकरण के सबसे महान सिद्धान्तकार माने जाते हैं। वे संस्कृत के भी पण्डित थे। वे होयसला राजदरबार के प्रतिष्ठित कवि थे। कन्नड कवि कन्... | null | null | null |
null | Find the largest key in a dictionary | {'a':1, 'b':5, 'c':6, 'd':9} | def findLargestKey(d): # Initialize largest_key and largest_val largest_key = None largest_val = -1 # Iterate each key-value in dictionary for key, value in d.items(): # Initialize largest_key and largest_val if value > largest_val: largest_val = value largest_key = key return largest_key |
null | Using the given code, create a JavaScript to add an item to the data array. | let data = [ {name:"John", age:20}, {name:"Amy", age:21} ] | data.push({name: 'Bob', age: 25}); |
[HI Wikipedia] किरोड़ीमल महाविद्यालय
किरोड़ीमल महाविद्यालय दिल्ली विश्वविद्यालय के उत्तरी परिसर में स्थित एक प्रमुख महाविद्यालय है। इस महाविद्यालय के पढ़े छात्र-छात्राये देश विदेशो में अनेक महत्वपूर्ण पदों पर कार्यरत है। सन्दर्भ दिल्ली विश्वविद्यालय | null | null | null |
[DE Wikipedia] Ernst Paul Dörfler
Ernst Paul Dörfler (* 15. Mai 1950 in Kemberg) ist ein deutscher Autor und Umweltschützer und war Mitbegründer der Grünen Partei in der DDR. Leben Ernst Paul Dörfler wuchs in Meuro bei Bad Schmiedeberg auf und absolvierte in Pretzsch an der Elbe das Abitur. Er studierte 1968 bis 1973 ... | null | null | null |
null | Write a Python function to check if a given number is a prime number or not. A prime number is an integer greater than 1 which is not divisible by any other numbers. | 11 | def is_prime(n): #Check if n islarger than one if n > 1: # Check if n is divisible by any number between2 and n for i in range(2,n): if (n % i) == 0: return False else: return True else: return False |
null | Given a dictionary, create a program to find the longest word in Python. | {"hello": 5, "world": 5, "welcome": 7, "to": 2, "programming": 11} | def longest_word(dictionary):
longest = ""
for word in dictionary:
if len(word) > len(longest):
longest = word
return longest |
null | Write a Python program to predict whether a customer is likely to churn or not. | [
{'id':1, 'age':25, 'gender':'Male', 'priority':'High'},
{'id':2, 'age':28, 'gender':'Male', 'priority':'Low'},
{'id':3, 'age':35, 'gender':'Female', 'priority':'High'},
{'id':4, 'age':18, 'gender':'Female', 'priority':'Low'},
{'id':5, 'age':45, 'gender':'Male', 'priority':'Low'},
{'id':6, 'age':27, 'gender':'Female',... | import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.tree import DecisionTreeClassifier
# Load the data
data = [
{'id':1, 'age':25, 'gender':'Male', 'priority':'High'},
{'id':2, 'age':28, 'gender':'Male', 'priority':'Low'},
{'id':3, 'age... |
null | Write a Python program to solve a quadratic equation given the coefficients a, b, c? | import math
def solve_quadratic(a, b, c):
# calculate discriminant
d = (b**2) - (4*a*c)
# find two solutions
sol1 = (-b-math.sqrt(d))/(2*a)
sol2 = (-b+math.sqrt(d))/(2*a)
return sol1, sol2 | |
[CS Wikipedia] Quend
Quend je francouzská obec v departementu Somme v regionu Hauts-de-France. V roce 2010 zde žilo 1 381 obyvatel. Vývoj počtu obyvatel Související články Seznam obcí v departementu Somme Externí odkazy Reference Obce v departementu Somme Přímořská letoviska ve Francii | null | null | null |
null | Write Python code to select values greater than 2 in a given list. | [1, 2, 3, 4, 5] | list = [1, 2, 3, 4, 5]
result = [value for value in list if value > 2]
print(result) |
null | Create a Python program to compare two strings. | def compare_strings(s1, s2):
if len(s1) != len(s2):
return False
for i in range(len(s1)):
if s1[i] != s2[i]:
return False
return True | |
[HI Wikipedia] सत्यमंगलम
सत्यमंगलम (Sathyamangalam) भारत के तमिल नाडु राज्य के ईरोड ज़िले में स्थित एक नगर है। यह पूर्वी घाट के चरणों में भवानी नदी के किनारे बसा हुआ है। इन्हें भी देखें ईरोड ज़िला सन्दर्भ ईरोड ज़िला तमिल नाडु के शहर ईरोड ज़िले के नगर | null | null | null |
[EN Wikipedia] Vidmantas Jažauskas
Vidmantas Jažauskas (born 30 November 1961 in Biržai, Lithuanian SSR) is a Lithuanian painter, book illustrator, poet, and social activist. Biography In 1991, he graduated from the Vilnius Art Institute. He teaches at the Biržai Vladas Jakubėnas Music School. Since 1982, he has parti... | null | null | null |
null | Create a function to convert an XML string to a JSON object. | import xmltodict def xmlToJsonObject(xmlStr): return xmltodict.parse(xmlStr) | |
[EN Wikipedia] Bistra (Bicaz)
The Bistra (in its upper course also: Bistra Mare) is a left tributary of the river Capra in Romania. It flows into the Capra in Telec. Its length is and its basin size is . References Rivers of Romania Rivers of Neamț County | null | null | null |
null | Replace the placeholder text with a valid statement that sets the default value for the 'count' parameter of the function | def prints(word, count=TODO): for i in range(count): print(word) | def prints(word, count=0): for i in range(count): print(word) |
null | Generate a hash for a given dictionary. | my_dict = {'name': 'John', 'age': 27, 'profession': 'programmer'} | import hashlib def generate_hash(my_dict): my_string = str(my_dict) res = hashlib.md5(my_string.encode()).hexdigest() return res print(generate_hash(my_dict)) |
null | Create a python script that compares two sets of input data (lists of numbers) and outputs the intersection set. | set1 = [1, 2, 3, 4, 5]
set2 = [3, 4, 5, 6, 7] | def find_intersection(set1, set2):
intersect_set = []
for num in set1:
if num in set2:
intersect_set.append(num)
return intersect_set
set1 = [1, 2, 3, 4, 5]
set2 = [3, 4, 5, 6, 7]
intersect_set = find_intersection(set1, set2)
print(intersect_set) # Output -> [3, 4, 5] |
null | Create a function to calculate the compound interest rate given the initial principal amount P, the annual interest rate r and the number of times compounding occurs in a year n. | def compound_interest(P, r, n): return P * (1 + (r/n))**(n*t) | |
[EN Wikipedia] Puriri River
The Puriri River is a river of the Waikato Region of New Zealand's North Island. It flows west close to the point where the Coromandel Peninsula joins the rest of the North Island, reaching the Waihou River east of Turua. 73% of the catchment is in forest and 27% in pasture. The main tribut... | null | null | null |
null | Write a PHP snippet to set cookie for the current page with the name "username" and value "foo". | setcookie('username', 'foo', 0); | |
[EN Wikipedia] Altaic languages
Altaic () is a controversial proposed language family that would include the Turkic, Mongolic and Tungusic language families and possibly also the Japonic and Koreanic languages. The hypothetical language family has long been rejected by most comparative linguists, although it continues... | null | null | null |
[EN Wikipedia] 1844 in Denmark
Events from the year 1844 in Denmark. Incumbents Monarch – Christian VIII Prime minister – Poul Christian Stemann Events Søren Kierkegaard publishes Philosophical Fragments. Undated Births JanuaryMarch 12 January – Louis Hasselriis, sculptor (died 1912) 13 January Peter Gottfred Ramm, mi... | null | null | null |
null | Write a Python program to sort the input list according to its length. | list = ["Hello", "World", "This is a test"] | list = ["Hello", "World", "This is a test"]
def sort_list_length(list):
'''
Function to sort the list according to its length
'''
return sorted(list, key=len)
if __name__ == "__main__":
list = ["Hello", "World", "This is a test"]
sorted_list = sort_list_length(list)
print(sorted_list) |
null | Implement a function that takes an integer n as input and returns a matrix of size nxn consisting of the natural numbers from 1 to n^2 in row major order. | n = 5 | [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 25]] |
null | Write code to sort a Python list of tuples based on their second element in the tuple. | list_of_tuples = [('a', 5), ('b', 1), ('c', 10)] | list_of_tuples.sort(key=lambda tup: tup[1]) |
null | Given an array of integers, write a function to determine whether the array is a palindrome. | array = [1,2,3,2,1] | def isPalindrome(array): return array == array[::-1] # reversed array |
[CS Wikipedia] Modulární programování
Modulární programování je technika návrhu softwaru, která zdůrazňuje rozdělení funkčnosti programu na nezávislé, zaměnitelné moduly, z nichž každý obsahuje vše nezbytné pro jediný aspekt požadované funkcionality. Koncepčně moduly představují oddělení zodpovědností a zlepšují udržo... | null | null | null |
null | Create a SQL table with the following schema: id (integer), name (string), city (string). | CREATE TABLE myTable ( id INTEGER, name VARCHAR(255), city VARCHAR(255) ); | |
null | Write a Java method to remove repeated elements from an array. | public static int[] removeDuplicates(int[] arr) { int n = arr.length; int[] temp = new int[n]; int j = 0; for (int i=0; i<n-1; i++){ if (arr[i] != arr[i+1]) temp[j++] = arr[i]; } temp[j++] = arr[n-1]; int[] res = new int[j]; for (int i=0; i<j; i++){ res[i] = temp[i]; } return res; } | |
null | How would you write a function in Python for generating a 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 return b | |
[HI Wikipedia] कृशनसर
कृशनसर (Krishansar, ) या कृष्णसर भारत के जम्मू व कश्मीर राज्य के गान्दरबल ज़िले के सोनमर्ग क़स्बे के पास स्थित एक स्वच्छ पर्वतीय झील है। ३,७१० मीटर पर स्थित यह झील प्रसिद्ध किशनगंगा नदी का सर्वप्रथम स्रोत है। इसकी लम्बाई ०.९५ किमी और चौड़ाई ०.६ किमी है। नाम 'कृशनसर' नाम 'कृष्णसर' का विकृत रूप है ... | null | null | null |
null | Develop a Python program to extract the last 3 elements of a given list and append them to the beginning of the list. | def move_last_3(list):
last3 = list[-3:]
del list[-3:]
list = last3 + list
return list | |
null | Given a positive integer number, generate the Fibonacci series. | def Fibonacci(n): if n<0: print("Incorrect input") # First Fibonacci number is 0 elif n==1: return 0 # Second Fibonacci number is 1 elif n==2: return 1 else: return Fibonacci(n-1)+Fibonacci(n-2) | |
null | What is the syntax for filtering a DataFrame using an OR condition in Pandas? | df.loc[(condition1) | (condition2)] | |
[CS Wikipedia] Jagdpanzer Jaguar 1
Jagdpanzer Jaguar 1 byl německý stíhač tanků. Spolu s bojovým vozidlem pěchoty Marder a Kanonenjagdpanzer patřil mezi úspěšné projekty SRN. Vozidla Jagdpanzer Jaguar 1 používá jen německá armáda. Literatura Zbraně 20. století: 600 nejznámějších zbraní světa. Praha : Ottovo nakladatel... | null | null | null |
null | Generate the first 10 prime numbers. | 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 | |
null | Create a function to decode a given string using the provided cipher. | decoding_cipher = { "x" : "a", "y": "b", "z" : "c" } string = "xyz" | def decode_string(decoding_cipher, string): result = "" for char in string: result += decoding_cipher[char] return result |
null | Write a web-scraping script in Python to fetch the first 100 data entries of a website. | import requests
from bs4 import BeautifulSoup
url = "THE_WEBSITE_URL"
# Get website content
response = requests.get(url)
# Parse the content of the response
soup = BeautifulSoup(response.text, 'html.parser')
# Find all html elements of the class "data-entry"
data_entries = soup.find_all(class_="data-entry")
# Fetch... | |
null | Create a Python script that will take two strings as input and checks if they are anagrams. | "cinema"
"iceman" | string1 = input("Enter first string: ")
string2 = input("Enter second string: ")
def isAnagram(string1, string2):
string1 = string1.lower()
string2 = string2.lower()
if sorted(string1) == sorted(string2):
return True
else:
return False
if isAnagram(string1, string2):
p... |
null | Write an HTML table to show a list of 3 books and respective authors. | Book 1: The Great Gatsby, Author: F. Scott Fitzgerald Book 2: The Catcher in the Rye, Author: J. D. Salinger Book 3: To Kill a Mockingbird, Author: Harper Lee | <table> <tr> <th>Book</th> <th>Author</th> </tr> <tr> <td>The Great Gatsby</td> <td>F. Scott Fitzgerald</td> </tr> <tr> <td>The Catcher in the Rye</td> <td>J.D. Salinger</td> </tr> <tr> <td>To Kill a Mockingbird</td> <td>Harper Lee</td> </tr> </table> |
null | Create a C++ code to display the following pattern. x xxx xxxxx xxxxxxx | #include <iostream> using namespace std; // Function to demonstrate printing pattern void triangle(int n) { // Outer loop to handle number of rows // n in this case for (int i=0; i<n; i++) { // Inner loop to handle number of columns // values changing acc. to outer loop for (int j=0; j<=i; j++ ) { // Printing stars cou... | |
null | How can you check if the given word is a palindrome in Python? | word = "madam" if word == word[::-1]: print("It is a palindrome") else: print("It is not a palindrome") | |
null | Edit the given JavaScript code to convert the input string’s first letter to uppercase. | let str = "hello world"; | let str = "hello world"; str = str[0].toUpperCase() + str.slice(1); |
null | Generate a Python program to sort an array of integers in linear time. | [5, 4, 3, 1, 2] | def sort(arr):
n = len(arr)
for i in range(n):
min_index = i # assuming current element is smallest
# look for smallest element in the rest of the array
for j in range(i+1, n):
if arr[j] < arr[min_index]:
min_index = j
arr[i... |
null | Create a two-player game of Blackjack in Python. | from random import shuffle
from itertools import product
deck = list(product(['A','2','3','4','5','6','7','8','9','10','J','Q','K'],['C','D','H','S']))
shuffle(deck)
player1_score = 0
player2_score = 0
def deal_cards(player):
card1 = deck.pop()
card2 = deck.pop()
player.append(card1)
player.append(ca... | |
null | Create a program in C to find the biggest of three numbers. | int max(int a, int b, int c) { int big = a; if(b > big) big = b; if(c > big) big = c; return big; } | |
null | Generate a python program that takes two sets of integers as input and outputs the intersection of those sets. | set1 = {1, 2, 3, 4}
set2 = {3, 4, 5, 6} | def intersection(set1, set2):
return set1 & set2
result = intersection(set1, set2)
print(result) |
null | Write a python program that takes a list of numbers as input and prints out the sum of the two numbers that are closest to zero. | nots = [1, 5, -3, 0 -7] | # Take the list of numbers
nots = [1, 5, -3, 0, -7]
# Sort the list
nots.sort()
# Set up variables to store the two closest values
closest1 = 0
closest2 = 0
# Iterate through the list
for val in nots:
# Check if the absolute value of the current number
# is closest to zero
if abs(val) < abs(closest1):
closest2... |
null | Write a Python program that simulates a coin flip game. The program should randomize a value between 0 and 1 and return "Heads" for values less than .5 and "Tails" for values greather than .5 | Not applicable | import random
def coin_flip():
if random.random() < 0.5:
return "Heads"
else:
return "Tails"
print(coin_flip()) |
null | Output the lexicographical order of a given array of strings. | words = ["apple", "banana", "cherry"] | apple, banana, cherry |
null | Write a Python program to query a MySQL database and produce a chart representing the results of the query. | The query is to calculate the total number of orders for each customer. The table name is 'orders'. | import mysql.connector
import matplotlib.pyplot as plt
# Connect to the database
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="password",
database="dbname"
)
# Create a cursor
mycursor = mydb.cursor()
# Execute a query
mycursor.execute("SELECT customer_id, COUNT(*) FROM order... |
null | Retrieve the 5th element from a list named 'numbers'. | numbers = [1, 2, 3, 4, 5, 6, 7, 8] | 5 |
null | Write an algorithm in Python to count how many words a given string contains. | def count_words(string): words = string.split() return len(words) | |
null | Parse the following JSON into a Python dictionary. | {
"name": "John",
"age": 28,
"hobbies": [
"Programming",
"Sports"
]
} | # import the json module
import json
# parse the json
json_dict = json.loads('{ "name": "John", "age": 28, "hobbies": [ "Programming", "Sports" ]}')
# print the parsed json
print(json_dict) |
null | Rewrite the code snippet using a different loop structure. | i = 0 while i < 5: print(i) i += 1 | for i in range(0, 5): print(i) |
null | Create an AI chatbot that can answer questions about the given topic "Covid-19". | Topic: Covid-19 | # Imports from chatterbot import ChatBot from chatterbot.trainers import ChatterBotCorpusTrainer # Create the AI Chatbot bot = ChatBot("CovidBot") # Train the bot on the corpus trainer = ChatterBotCorpusTrainer(bot) trainer.train("chatterbot.corpus.english.covid19") # Start the chatbot while True: user_input = input("U... |
null | How does JavaScript handle undeclared variables? | JavaScript will automatically create an undeclared variable if it is referenced in the code. The variable is then set to the undefined value. The variable cannot be set or accessed until it has been declared. The variable will also remain in the global scope. | |
null | Create a HTML form and assign 'onSubmit' handler to it. | <form onSubmit="alert('Form submitted')"> <!-- Form Content --> <input type="submit" value="Submit"> </form> | |
null | Design a code in Python to count the number of unique elements in a list. | numbers_list = [1, 2, 2, 5, 6, 6] | def count_unique_elements(numbers_list):
seen = set()
count = 0
for number in numbers_list:
if number not in seen:
seen.add(number)
count+=1
return count |
null | Suggest a Python code to create a list containing the first five positive numbers. | numbers = [] for i in range(1, 6): numbers.append(i) print(numbers) | |
null | Create a web scrapper in Python that collects all the blog posts from the given website and stores them in a SQLite database. | Website URL: https://blog.floydhub.com/ | import requests
import sqlite3
from bs4 import BeautifulSoup
# Get the web page content
url = 'https://blog.floydhub.com/'
page = requests.get(url)
# Parse the page
soup = BeautifulSoup(page.content, 'html.parser')
# Extract the posts
posts = soup.find_all('div', {'class': 'post-content'})
# Create a database conne... |
null | Create a web page with a navigation bar at the top. | <!DOCTYPE html> <html> <head> <title>Navigation Bar Demo</title> </head> <body> <nav> <ul> <li><a href="#">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Contact</a></li> </ul> </nav> <h1>Welcome!</h1> <p>This is a demo page with a navigation bar at the top.</p> </body> </html> | |
null | Write a python program to find the most common words in a given text. Input should be given as a string and output should be a list of words in descending order of frequency. | text = 'This is a text to find the most common words in the given text. The output should be a list of words in descending order of frequency' | from collections import Counter
def find_most_common_words(text):
words = text.split()
counter = Counter(words)
return counter.most_common()
print(find_most_common_words(text))
# Output: [('a', 2), ('the', 2), ('in', 2), ('of', 2), ('most', 1), ('This', 1), ('is', 1), ('text', 1), ('find', 1), ('common', 1), ('wo... |
[EN Wikipedia] Gmina Gostynin
Gmina Gostynin is a rural gmina (administrative district) in Gostynin County, Masovian Voivodeship, in east-central Poland. Its seat is the town of Gostynin, although the town is not part of the territory of the gmina. The gmina covers an area of , and as of 2006 its total population is 1... | null | null | null |
null | Write an efficient Python program to remove duplicate characters from the given string. | String: Hello world | He lwrd |
null | Implement a program in Python that takes a string as an input and prints out the length of the longest word in the string. | string = "The quick brown fox jumps over the lazy dog" | def longest_word(string):
words = string.split(" ")
max_length = 0
longest_word = ""
for word in words:
if(len(word) > max_length):
max_length = len(word)
longest_word = word
print("Longest word is {} with length {}".format(longest_word,max_length)) |
null | Given a list of numbers, write a program which partitions the list into two parts, such that the sum of the elements in the first part exceeds the sum of the elements in the second part. | def partition(lst): left_sum, right_sum = 0, sum(lst) for i in range(len(lst)-1): left_sum += lst[i] right_sum -= lst[i] if left_sum > right_sum: return lst[:i+1], lst[i+1:] return None | |
[HI Wikipedia] शिव
शंकर या महादेव अरण्य संस्कृति जो आगे चल कर सनातन शिव धर्म नाम से जाने जाते है में सबसे महत्वपूर्ण देवताओं में से एक है। वह त्रिदेवों में एक देव हैं। इन्हें देवों के देव महादेव भी कहते हैं। इन्हें भोलेनाथ, शंकर, महेश, भिलपती, भिलेश्वर,रुद्र, नीलकंठ, गंगाधार आदि नामों से भी जाना जाता है। तंत्र साधना म... | null | null | null |
[HI Wikipedia] काशी
काशी नगरी वर्तमान वाराणसी शहर में स्थित पौराणिक नगरी है। इसे संसार के सबसे पुरानी नगरों में माना जाता है। भारत की यह जगत्प्रसिद्ध प्राचीन नगरी गंगा के वाम (उत्तर) तट पर उत्तर प्रदेश के दक्षिण-पूर्वी कोने में वरुणा और असी नदियों के गंगा संगमों के बीच बसी हुई है। इस स्थान पर गंगा ने प्राय: चार मील का... | null | null | null |
null | Write a SQL query to select all rows in the table 'students' whose marks are greater than 25. | SELECT * FROM students WHERE marks > 25; | |
null | Design a python script to calculate BMI of a person. | def calculate_bmi(height, weight):
bmi = weight / ((height/100) ** 2)
return bmi | |
null | How does the fadeIn() function work in jQuery? | The fadeIn() function in jQuery is used to gradually increase the opacity of an element from hidden to visible, in a specified duration. The function works by adjusting the CSS property for opacity for the element, from 0 to 1, over a specified duration of time. | |
[HI Wikipedia] और भी ग़म हैं ज़माने में
और भी ग़म हैं ज़माने में १९८० के दशक के आरम्भिक सालों में एक भारतीय टेलिविज़न धारावाहिक था जो दूरदर्शन पर प्रसारित किया जाता था। इसकी ३२ कड़ियाँ प्रसारित हुई जिनमें मनोरंजन और सामाजिक शिक्षा का मिश्रण हुआ करता था। हर दो सप्ताह में एक बार प्रसारित होने वाले इस धारावाहिक की हर किश... | null | null | null |
null | Resolve the issue in the code causing a "TypeError" to be thrown | names = ["John", "James", 10] for name in names: print(name) | """ Resolve the issue in the code causing a TypeError to be thrown """ names = ["John", "James", 10] for name in names: # Check the type of the element and only display it if it's a string if type(name) == str: print(name) """ Output: John James """ |
null | What is the purpose of neural networks? | The purpose of neural networks is to recognize patterns in data and make predictions or decisions based on those patterns. Neural networks are an approach to artificial intelligence, modeled after the neural networks in the human brain. They allow computers to learn by processing large amounts of data and identifying p... | |
null | Given a large string S, find the total number of occurrences of a pattern p in S. | S = “Mississippi”, p = “si” | //Function to find the total number of occurrences of a pattern p in a large string S function findOccurrences(S, p) { let count = 0; let initialIndex = 0; while (S.indexOf(p, initialIndex) !== -1) { initialIndex = S.indexOf(p, initialIndex) + 1; count++; } console.log(count); } findOccurrences('Mississippi', 'si'); //... |
null | Write a 50 lines of code snippet in Python that implements linear search algorithm. | A list of integers: [1, 4, 3, 2, 5] | def linear_search(arr, target):
for i in range(len(arr)):
if arr[i] == target:
return i
return -1
# Test array
arr = [1, 4, 3, 2, 5]
target = 3
# Function call
result = linear_search(arr, target)
if result != -1:
print ("Element is present at index", result)
else:
print ("Element is not present in a... |
null | Modify the following Java program to find the area of a rectangle. | public class Area { public static void main(String[] args) { double radius = 10; double area = 3.14 * radius * radius; System.out.println("The area of the circle = "+area); } } | public class Area { public static void main(String[] args) { double length = 10; double width = 5; double area = length * width; System.out.println("The area of the rectangle = "+area); } } |
null | Rewrite the following jQuery code to its vanilla JavaScript equivalent. | $("#list li").each(function(){ //some code }); | document.querySelectorAll("#list li").forEach(function (el) { //some code }); |
null | Create a block of HTML code to display a table with 6 columns and 10 rows. | <table> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> <th>Column 6</th> </tr> </thead> <tbody> <tr> <td>Row 1</td> <td>Row 1</td> <td>Row 1</td> <td>Row 1</td> <td>Row 1</td> <td>Row 1</td> </tr> <tr> <td>Row 2</td> <td>Row 2</td> <td>Row 2</td> <td>Row 2</td> <t... | |
null | Create a Python program to detect the occurrence of a certain word in a collection of text documents. | A collection of 10 text documents from a news website and the word is "coronavirus". | import os
def detect_coronavirus(input_dir):
# input_dir - The directory containing the text documents
total_occurrences = 0
# Iterate through each file in the input_dir
for file in os.listdir(input_dir):
file_path = os.path.join(input_dir, file)
# Read the file
with open(file... |
null | Develop a REST API in Python that fetches the number of likes of a specific post. | from flask import Flask
import requests
app = Flask(__name__)
@app.route('/post-likes/<int:id>', methods=['GET'])
def post_likes(id):
response = requests.get('https://api.example.com/likes?id={id}')
return response.json()
if __name__ == '__main__':
app.run() | |
null | Modify the given JavaScript code to display "Hello World" using alert. | let message = 'Hi'; alert(message); | let message = 'Hello World'; alert(message); |
[EN Wikipedia] Dechloromonas
Dechloromonas is a genus in the phylum Pseudomonadota (Bacteria). Etymology The name Dechloromonas derives from:Latin pref. de, from; Neo-Latin noun chlorinum (from Greek adjective chlorōs, green), chlorine; Neo-Latin pref. chloro-, pertaining to chlorine; Latin feminine gender noun monas ... | null | null | null |
null | In Python, parse the following XML document and extract the book title and author. | <book>
<title>Title1</title>
<author>Author1</author>
</book> | # import the necessary libraries
import xml.etree.ElementTree as ET
# Parse the XML document
root = ET.fromstring(xml_doc)
for book in root:
if book.tag == 'title':
title = book.text
elif book.tag == 'author':
author = book.text
print(f"Book Title: {title}, Author: {author}") |
null | Write a SQL query to select the employee names and IDs from the table 'employees' where the name contains "John". | SELECT name, id FROM employees WHERE name LIKE '%John%'; | |
null | Edit the following Python code to reverse the list. | list1 = [1,2,3,4,5,6] | list1 = [1,2,3,4,5,6]
# Reversing the list
list1 = list1[::-1] # Output: [6, 5, 4, 3, 2, 1] |
null | Create an SQL statement to select the title and description of all movies with a rating greater than 3. | SELECT title, description FROM movies WHERE rating > 3; | |
null | Create a function for printing each letter of a string on a separate line. | str = "Hello World" | def print_letter_separately(str): for letter in str: print(letter) # Output print_letter_separately(str) |
null | Create a HTML page that has a table displaying the names, phone numbers and email addresses of 5 employees. | <html> <head> <title>Employees</title> </head> <body> <h1>Employees</h1> <table> <tr> <th>Name</th> <th>Phone</th> <th>Email</th> </tr> <tr> <td>John Doe</td> <td>123-456-7890</td> <td>john.doe@example.com</td> </tr> <tr> <td>Jane Doe</td> <td>123-456-0987</td> <td>jane.doe@example.com</td> </tr> <tr> <td>Jeff Smith</t... | |
null | Write a function in Python to return the first n digits of the Fibonacci sequence. | n = 5 | 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 return b fibonacci(n) |
null | Create a function to filter out any strings containing the word "the" from a list of strings. | def filter_the(string_list): filtered_list = [] for string in string_list: if "the" not in string: filtered_list.append(string) return filtered_list | |
null | Generate code to prompt user input using Python. | Not applicable | name = input('What is your name? ')
print('Hello', name, '!') |
null | Create a loop that prints out numbers from 0 to 15, except skip numbers 6, 7, and 12. | for num in range(16): if num not in [6, 7, 12]: print(num) | |
null | What are the three main principles of OOP? | The three main principles of Object Oriented Programming (OOP) are encapsulation, inheritance, and polymorphism. Encapsulation is the process of wrapping data and functions together into one unit. Inheritance is the process of allowing a class to inherit the properties and behavior of a parent class. Polymorphism is th... | |
null | Create a simple Python script that prints out verses from the poem "Twinkle Twinkle Little Star". | #print the verses
print("Twinkle, twinkle, little star,")
print("How I wonder what you are!")
print("Up above the world so high,")
print("Like a diamond in the sky.")
print("Twinkle, twinkle, little star,")
print("How I wonder what you are!") |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.