text
stringlengths
141
2.89k
⌀
instruction
stringlengths
19
1.5k
⌀
input
stringlengths
0
800
⌀
output
stringlengths
1
2.5k
⌀
[HI Wikipedia] सीवान सीवान(𑂮𑂲𑂫𑂰𑂢) या सिवान(𑂮𑂱𑂫𑂰𑂢) भारत गणराज्य के बिहार प्रान्त में सारन प्रमंडल के अंतर्गत एक शहर है। यह सीवान ज़िले का मुख्यालय है, जो बिहार के पश्चिमोत्तरी छोर पर उत्तर प्रदेश का सीमावर्ती जिला है। सिवान दाहा नदी के किनारे बसा है। इसके उत्तर तथा पूर्व में क्रमश: बिहार का गोपालगंज तथा सारण ...
null
null
null
null
Write a test suite to test an arithmetic function that takes two arguments and returns the sum.
import unittest class TestArithmeticFunction(unittest.TestCase): def test_sum(self): self.assertEqual(arithmetic_function(2, 5), 7) self.assertEqual(arithmetic_function(-4, 9), 5) self.assertEqual(arithmetic_function(-2, 0), -2) if __name__ == '__main__': unittest.main()
null
Write a function to output "Thank you" three times.
def say_thanks(): for i in range(3): print("Thank you")
null
Write a function in Python that takes an input list, multiplies each item in the list by two, and returns the resulting list.
def double_list(lst): return [x * 2 for x in lst]
null
Create an HTML page that displays two columns consisting of the numbers 1 to 10.
<!DOCTYPE html> <html> <head> <title>Two columns of numbers from 1 to 10</title> </head> <body> <h1>Two columns of numbers from 1 to 10</h1> <table> <tr> <th>Column 1</th> <th>Column 2</th> </tr> <tr> <td>1</td> <td>6</td> </tr> <tr> <td>2</td> <td>7</td> </tr> <tr> <td>3</td> <td>8</td> </tr> <tr> <td>4</td> <td>9</td...
[CS Wikipedia] Didaktika Didaktika je teorie vzdělávání, která se zabývá formami, postupy a cíli vyučování. Je součástí pedagogiky, zabývající se metodami a formami školního vyučování. Didaktika je pojem odvozený z řeckého slova didasko, které znamená učím nebo vyučuji. Předmět didaktika je nezbytnou součástí studia k...
null
null
null
null
Develop a program to determine if a given year is a leap year.
year = 2024
# Determining if a year is a leap year # Assigning the current year year = 2024 # Checking if the year is a leap year if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): print(year, "is a leap year") else: print(year, "is not a leap year")
null
How would you write a query in SQL to return the names of all customers who have purchased over $100 in the last month?
SELECT customer_name FROM customers WHERE orders.amount > 100 AND orders.date > NOW() - INTERVAL 1 MONTH;
[EN Wikipedia] Nachum Heiman Nachum Heiman (; May 6, 1934 – August 17, 2016) was an Israeli composer and musician. Some of the over 1,000 songs he composed have become classics of Israeli folk music. Biography Nachum (Nakhche) Heiman was born in Riga, Latvia in 1934 to a musical family that immigrated to Mandatory Pal...
null
null
null
[EN Wikipedia] List of Israeli films of 1975 A list of films produced by the Israeli film industry in 1975. 1975 releases Unknown premiere date See also 1975 in Israel References External links Israeli films of 1975 at the Internet Movie Database Israeli Film 1975
null
null
null
null
Generate a random string of 12 characters using Python.
import string import random ''.join(random.choices(string.ascii_letters + string.digits, k=12))
null
Develop a ML model in Python for predicting the winning team of football matches. Use data from the past 5 years of the Premier League.
Not applicable
import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.ensemble import GradientBoostingClassifier # Load data data = pd.read_csv('data.csv') # Select features features = data[['home_team_goals', 'away_team_goals', 'home_team_possession', 'away_team_possession', ...
null
Design a regex pattern to check if a given string is a valid URL or not.
pattern = r'^(https?:\/\/)[\da-z\.-]+\.[a-z\.]{2,}\/?[\/\w \.-]*'
null
Write an SQL query to select all the customers who are from the US.
SELECT * FROM customers WHERE country = 'US';
[CS Wikipedia] Stanislav Kamarýt Stanislav Kamarýt (10. listopadu 1883 Velešín – 30. července 1956 Havlíčkův Brod) byl český esperantista, doktor filozofie a ředitel gymnázia v Chotěboři. Byl vůdčí osobnost československého esperantského hnutí. Dílo Díla v esperantu Stanislav Kamarýt byl mimo vlastní tvorby také redak...
null
null
null
null
Write a Python program to randomly split a list into two parts.
[1, 2, 3, 4, 5, 6, 7, 8]
import random def split_list(input_list): index = random.randint(0, len(input_list)-1) part1 = input_list[:index] part2 = input_list[index:] return part1, part2 input_list = [1, 2, 3, 4, 5, 6, 7, 8] print("Original list :", input_list) result1, result2 = split_list(input_list) print("\nPart 1 :", resu...
null
Modify the code so that it checks if the number input is an integer or a decimal.
number = input("Please input a number: ")
number = input("Please input a number: ") if type(number) == int: print("Input is an integer") else: print("Input is a decimal")
null
Create a MySQL query to get the maximum salary from the employees table section.
Table structure: employees id | name | department | salary |
SELECT MAX(salary) FROM employees;
null
Create a class called 'Animal' that stores the attributes age and type.
class Animal: def __init__(self, age, type): self.age = age self.type = type
null
Create a game using only Python code.
Not applicable
import random import time def game_loop(): game_running = True display_intro() while game_running: user_input = input(" What action do you choose? ") if user_input == "run": start_running() elif user_input == "look": enemy_random_number = random.randint(1, 10...
null
Generate a Python program that takes a string and capitalizes the first character of each word.
"this is an example"
def capitalize_string(str): words = str.split(' ') capitalized_words = [word.capitalize() for word in words] return " ".join(capitalized_words) capitalized_string = capitalize_string("this is an example") print(capitalized_string)
null
Create an algorithm with pseudocode to find maximum and minimum element of an array.
Algorithm findMaxMin(arr) Input: arr - an array of integers Output: maxEle - the maximum element in the array, minEle - the minimum element in the array Begin maxEle <- arr[0] minEle <- arr[0] for i = 0 to length(arr)-1 do if arr[i] > maxEle then maxEle <- arr[i] end if if arr[i] < minEle then minEle <- arr[i] end if e...
[HI Wikipedia] भीमस्वामी भीमस्वामी संस्कृत कवि थे। छठी शताब्दी ई० के अंतिम चरण में इनकी स्थिति मानी जाती है। इनका 'रावणार्जुनीय काव्य' प्रसिद्ध है। २७ सर्गों वाले इस काव्य में कार्तवीर्य अर्जुन तथा रावण के युद्ध का वर्णन है। भट्टिकाव्य की तरह इस काव्य में भी काव्य के बहाने संस्कृत व्याकरण के नियमों के उदाहरण उपस्थित क...
null
null
null
null
Rewrite the following Javascript code as a Python code that solves the same problem. Given an array of numbers, find the square root of each number and print it.
[2, 3, 4, 5]
import math numbers = [2, 3, 4, 5] for number in numbers: print(math.sqrt(number)) # Output # 1.414 # 1.732 # 2.000 # 2.236
null
Generate a Python code to convert list of strings to list of integers.
strings = ['23', '45', '7', '67']
def convert_to_ints(strings): ints = [] for s in strings: ints.append(int(s)) return ints
[CS Wikipedia] Jaroslav Simonides Jaroslav Simonides (17. května 1915 Holešov – 25. května 1996 v Praze ), organizátor společenského života, velmi plodný překladatel literatury z několika jazyků, především polštiny. Životopis Po absolvování gymnasia v rodném městě nastoupil na Filozofickou fakultu Univerzity Karlovy, ...
null
null
null
null
Create a machine learning model in Python that can classify a set of samples into two classes.
Sample1: 0.8, 0.1, 0.3 Sample2: 1.0, 0.4, 0.7 Sample3: 0.4, 0.5, 0.9 Sample4: 0.2, 0.7, 0.8
import numpy as np from sklearn.svm import SVC X = np.array([[0.8, 0.1, 0.3], [1.0, 0.4, 0.7], [0.4, 0.5, 0.9], [0.2, 0.7, 0.8]]) y = np.array([0, 1, 0, 1]) model = SVC() model.fit(X, y)
null
Implement a naive bayes classifier in Python.
class NaiveBayesClassifier: """ A simple Naive Bayes classifier implementation """ def __init__(self): self.classes = [] self.word_counts = {} self.priors = {} def fit(self, X, y): """ Train the classifier X: List of documents y: List of labe...
null
Rewrite the following code to use more efficient loops.
for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { System.out.println("hi"); } }
for (int i = 0; i < 100; i++) { System.out.println("hi"); }
[HI Wikipedia] जयपुर जयपुर शहर भारत के सबसे बड़े राज्य राजस्थान की राजधानी है। जयपुर राजस्थान का जोधपुर महानगर के बाद दूसरा बड़ा शहर है। जयपुर को पिंक सिटी अथवा गुलाबी नगरी भी कहते है, इसको सबसे पहले स्टैनली रीड ने पिंक सिटी बोला था । जयपुर की स्थापना आमेर के महाराजा सवाई जयसिंह (द्वितीय) ने की थी। यूनेस्को द्वारा जुल...
null
null
null
null
Create a Python script to print the following output.
for x in range(10): for y in range(10): print("*" if (x + y) % 2 == 0 else " ", end="") print("")
null
Write a SQL query to find the average credit score of users who are 18 years or younger.
SELECT AVG(credit_score) FROM users WHERE age <= 18
null
Write a Python script to calculate the total and the average of an array of numbers.
arr = [56, 23, 89, 17, 13, 10]
total=sum(arr) avg=sum(arr)/len(arr) print("Total of the array elements is: "+str(total)) print("Average of the array elements is: "+str(avg))
null
Create a Python program to implement a web scraper for obtaining the latest news headlines from CNN.
Not applicable
import requests from bs4 import BeautifulSoup # Function to web scrape news from CNN def scrape_cnn(): url = "https://www.cnn.com/" page = requests.get(url) if page.status_code != 200: return False soup = BeautifulSoup(page.content, 'html.parser') headlines = [] for headline in soup.fin...
null
Translate the following MATLAB code snippet into R.
A = [1 2 3; 4 5 6; 7 8 9]; B = A(1, :)
A <- matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 9), nrow = 3, ncol = 3) B <- A[1,]
[DE Wikipedia] Marseille Blue Stars Die Marseille Blue Stars, auf französisch auch Blue Stars de Marseille, sind ein American-Football-Team aus dem französischen Marseille. Die erste Mannschaft spielt seit 2018 in der Division Elite, die Heimspiele finden im Stade Pierre-Delort statt. Die U19 wurde 2015 und 2022 franz...
null
null
null
[HI Wikipedia] फ़ोर्तूना फ़ोर्तूना (अंग्रेज़ी : :en:Fortuna फ़ोर्चूना, लातिनी : Fortuna फ़ोर्तूना ) प्राचीन रोमन धर्म की प्रमुख देवियों में से एक थीं। वो भाग्य और दुनिया के छलावे की देवी थीं। उनके समतुल्य प्राचीन यूनानी धर्म की देवी थीं टाइकी। रोम के देवी-देवता रोमन धर्म
null
null
null
null
Validate whether the string contains only alphabets or not.
myString = "abc123"
def check_string_alphabets(myString): for character in myString: if (not character.isalpha()): return False return True myString = "abc123" if (check_string_alphabets(myString)): print("String contains only alphabets") else: print("String contains numbers")
null
Write a Python program to find the most efficient path for a robot to take from its current location to the destination
start = (4, 2) end = (9, 9)
# Function to find the most efficient path def find_path(start, end): # Current location of the robot x = start[0] y = start[1] # Destination coordinates goal_x = end[0] goal_y = end[1] # set to record the cells already visited visited = set() # define a queue to store the tuple ...
null
Write a python program that selects five random elements from a list and prints them.
my_list = [1, 3, 5, 8, 7, 2, 10, 4, 6, 9]
import random my_list = [1, 3, 5, 8, 7, 2, 10, 4, 6, 9] random.shuffle(my_list) for i in range(5): print(my_list[i])
null
Create a program which finds patterns in a stream of numbers and prints out the start of the pattern.
87, 88, 89, 87, 88, 89, 87, 88, 89
Pattern detected: 87, 88, 89. Starting at index 0.
[EN Wikipedia] Governor Penn Governor Penn may refer to: John Penn (governor) (1729–1795), Governor of Colonial Pennsylvania from 1763 to 1771 and from 1773 to 1776 Richard Penn Sr. (1706–1771), Proprietary and Titular Governor of the Province of Pennsylvania from 1746 to 1771 See also Dancia Penn (born 1951), Deputy ...
null
null
null
null
Write a python function to reverse the words in a given sentence.
sentence = "hello world how are you"
def reverseWords(sentence): words = sentence.split(' ') words = words[::-1] return ' '.join(words) print(reverseWords(sentence))
null
Create a function that takes two strings's, two string length's and returns true if the second string is a rotation of the first.
string1 = "Hello World" string2 = "WorldHello" length1 = 11 length2 = 11
def isRotation(string1, string2, length1, length2): if length1 == length2 and len(string1)>0: string1string1 = string1 + string1 return string2 in string1string1
null
Write a Python script that generates a chess board with 8 rows and 8 columns of squares.
Not applicable
# create 8 rows for row in range(8): # create 8 columns for col in range(8): # create a square square = {"row": row, "col": col} # If it is the first row or the last row of the board if row == 0 or row == 7: # if it is an odd square if (col % 2) == 0: # set the square to white ...
null
Create a table in PostgreSQL using the following columns: id, name, age and address.
CREATE TABLE employees ( id SERIAL PRIMARY KEY, name VARCHAR(50) not null, age INTEGER not null, address VARCHAR(50) );
null
Create a function to generate random numbers from 0-99.
import random def random_number(): return random.randint(0,99)
null
This code defines a class called ChefConf that has methods to load and validate data, as well as getters and setters for various fields. To use this class, create an instance of it and call its methods as needed. Make sure to provide the necessary data to the load_data method before calling validate.
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- # This file is part of Guadalinex # # This software is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, ...
null
Develop a C# function to check if a given number is Armstrong or not. An Armstrong number is one which is equal to the sum of its digits raised to the power of the number of digits.
static bool IsArmstrong(int num) { int origNum = num; int sum = 0; int digits = 0; while (num != 0) { digits++; num /= 10; } num = origNum; while (num != 0) { sum +=Math.Pow(num % 10, digits); num /= 10; } if (sum== origNum) return true; return false; }
null
Update the given list of numbers such that the first number is subtracted from the second one, the third is multiplied by the fourth, and the result is added to the fifth.
[2, 5, 4, 7, 9]
[2, 5, 28, 7, 37]
null
Update the below HTML snippet to make all the section heading elements center aligned.
<h1>Section 1</h1> <h2>Section 2</h2> <h3>Section 3</h3>
<h1 style="text-align: center;">Section 1</h1> <h2 style="text-align: center;">Section 2</h2> <h3 style="text-align: center;">Section 3</h3>
null
Create a regular expression to validate an e-mail address.
^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$
null
Create a program in Python to generate an infinite sequence of random numbers.
Not applicable
# This program will generate an infinite sequence of random numbers import random # Generate infinite sequence of random numbers def rand_seq(): while True: yield random.random() # Print 10 random numbers for i in range(10): print(next(rand_seq()))
null
Rewrite this query using OR operator.
SELECT * FROM customers WHERE country = "USA" AND state = "NC"
SELECT * FROM customers WHERE country = "USA" OR state = "NC"
null
Describe the difference between static and dynamic programming
Static programming is when all of the instructions to perform a task are written out before the program is executed. In static programming, the order of instructions and the number of instructions does not change during execution. Dynamic programming is when the instructions and number or order of instructions can chan...
[CS Wikipedia] Hydrostatický tlak Hydrostatický tlak je tlak, který vzniká v kapalině její tíhou. Obdoba hydrostatického tlaku působícího v kapalinách se vyskytuje také v plynech, kde se označuje jako aerostatický tlak a pro tlak v atmosféře jako atmosférický tlak. Tlak působící v taveninách kovů se označuje jako meta...
null
null
null
null
Create an array of 5 random numbers between 1 and 10 and output it to the console.
let arr = []; for (let i = 0; i < 5; i++) { arr.push(Math.floor(Math.random() * 10 + 1)); } console.log(arr);
null
Find the closest pair of points from a list of points in Python?
points = [(1,1), (3,3), (-2, 4), (-3, -2), (2, 4)]
def closest_pair(points): min_distance = float('inf') n = len(points) for i in range(n-1): for j in range(i+1, n): distance = ((points[i][0] - points[j][0])**2 + (points[i][1] - points[j][1])**2)**0.5 if distance < min_distance: ...
null
Given a 2D matrix of integers, retrive the maximum sum submatrix.
[[2,-2,3,4],[-4,-3,1,1],[-1,5,5,-3]]
def max_sum_submatrix(matrix): rows, columns = len(matrix), len(matrix[0]) dp = [[0] * columns for _ in range(rows)] for i in range(rows): for j in range(columns): dp[i][j] = matrix[i][j] if i > 0: dp[i][j] += dp[i-1][j] if j > 0: dp[i][j] += dp[i][j-1] if i > 0 and j > 0: dp[i][j] -= dp[i-1][j-1] max_sum = float('-inf...
[HI Wikipedia] क्यूपिड क्यूपिड (लातिनी: Cupidus कूपिदुस) प्राचीन रोमन धर्म के देवताओं में से एक हैं। वह कामदेव की तरह प्रेम और काम-वासना के देवता हैं। उनके समतुल्य प्राचीन यूनानी धर्म के देवता थे ईरोस। उनका एक और लातिनी नाम है, आमोर। ये रोमन देवता ज्यूपिटर और देवी वीनस के पुत्र माने जाते हैं। उनको एक पंख लगे बच्चे की ...
null
null
null
[EN Wikipedia] Allah Allah (; , , ) is the common Arabic word for God. In the English language, the word generally refers to God in Islam. The word is thought to be derived by contraction from al-ilāh, which means "the god", and is linguistically related to the Aramaic words Elah and Syriac (ʼAlāhā) and the Hebrew wor...
null
null
null
null
Construct a function which will take the name of a month as a parameter and return the number of days in that month.
function daysInMonth(month) { switch (month) { case "January": case "March": case "May": case "July": case "August": case "October": case "December": return 31; case "April": case "June": case "September": case "November": return 30; case "February": return 29; default: throw new Error('Invalid month'); } }
[CS Wikipedia] Antonin Artaud Antonin Artaud (výslovnost: arto, plným jménem Antoine Marie Joseph Artaud, 4. září 1896, Marseille, Francie – 4. března 1948, Ivry-sur-Seine) byl francouzský básník a divadelník; představitel francouzské meziválečné avantgardy, volně řazený do okruhu tzv. „prokletých básníků“. Život a dí...
null
null
null
null
Create an object data structure in JavaScript to represent a student and store details such as student's name, age, gender, and program.
let student = { name: '', age: 0, gender: '', program: '' };
null
Write a function in Python Web scripting to update the value of a given list.
my_list = [1,2,3] new_value = 5
def update_list(my_list, new_value): my_list[-1] = new_value return my_list my_list = [1,2,3] new_value = 5 updated_list = update_list(my_list, new_value) print(updated_list)
null
Build a web application using Django and React that displays a list of products and provides user authentication.
Not applicable
# Setup Django # Create a Django project django-admin startproject myproject # Create an app inside the Django project cd myproject python manage.py startapp products # Add the app to INSTALLED_APPS in the settings.py file INSTALLED_APPS = [ 'products.apps.ProductsConfig', # other apps ] # Add the authentic...
null
Aggregate and calculate the mean of the following array by grouping them by the key 'region'.
array = [ {'name': 'John', 'region': 'West', 'score': 4}, {'name': 'Jane', 'region': 'West', 'score': 10}, {'name': 'Bob', 'region': 'East', 'score': 5}, {'name': 'Alice', 'region': 'East', 'score': 20} ]
import pandas as pd df = pd.DataFrame(array) mean_by_region = df.groupby('region')['score'].mean() print(mean_by_region)
[EN Wikipedia] Nkiru Sylvanus Nkiru Sylvanus (born 21 April 1985) is a Nigerian actress and politician. She has featured in over two hundred movies and had been nominated for Best Actress of the Year at the Africa Magic Viewers Choice Awards and Best Actress in a Leading Role at the Africa Movie Academy Awards. Early ...
null
null
null
[DE Wikipedia] Evangelische Kirche (Wolfenhausen) Die Evangelische Kirche in Wolfenhausen im Taunus, Gemeinde Weilmünster im Landkreis Limburg-Weilburg in Hessen, ist eine einschiffige barocke Kirche. Sie wurde 1752 errichtet. Die Kirchengemeinde gehört zum Dekanat an der Lahn in der Propstei Nord-Nassau der Evangelis...
null
null
null
null
Write a Ruby program to swap two given variables a and b.
a = 10, b = 5
a, b = b, a puts a # => 5 puts b # => 10
[DE Wikipedia] Phalerae Die Phalerae (lat. nur im Plural überliefert; griech. Plural τὰ φάλαρα tà phálara „die Metallbuckel“, Singular phálaron) sind in der griechisch-römischen Antike runde Platten aus Gold, Silber oder einem anderen Metall mit erhabenen Verzierungen oder Gravuren. Nach Sueton war es ursprünglich ein...
null
null
null
null
Generate an SQL query to retrieve the data
Retrieve the name and salary of employees whose salary is more than $50000
SELECT name, salary FROM employees WHERE salary > 50000;
null
Use a for loop to sum the numbers in the list [4, 6, 5, 8].
sum = 0 for num in [4,6,5,8]: sum = sum + num print("The sum is:",sum)
null
Develop a Python program to find the common elements in two lists.
List 1: [3, 9, 15, 21, 27] List 2: [21, 7, 13, 29, 31]
common_elements = [] # using loop for i in [3, 9, 15, 21, 27]: for j in [21, 7, 13, 29, 31]: if i == j: common_elements.append(i) # printing common elements print(common_elements) # Output: [21]
null
Describe a greedy algorithm
A greedy algorithm is an approach to solving a problem that involves making decisions based on the best immediate payoff, without considering the overall cost. It follows the principle of 'greedy', which involves making a decision with the largest immediate benefit and disregarding the overall cost of the solution. Gre...
null
Design an API in Python that takes two parameters: a list of strings and a string. The API should return the number of times the string is seen in the list.
List of Strings: ["this", "is", "a", "word"] String: "a"
def find_string_count(string_list, target_string): count = 0 for item in string_list: if item == target_string: count += 1 return count list_of_strings = ["this", "is", "a", "word"] target_string = "a" result = find_string_count(list_of_strings, target_string) print('Number of occurrences of', target_string, '...
null
Develop a Python program to check if a number is divisible by 3.
def is_divisible_by_3(num): if num % 3 == 0: return True return False
null
Explain recursion in programming.
Recursion is a programming technique where a function calls itself, either directly or indirectly. It is used to solve problems that involve repetition or breaking down a problem into simpler sub-problems. Recursion can be used to solve a wide range of problems, from sorting algorithms to defining recursive data struct...
null
Write pseudo code for finding the maximum element in an array.
START SET max_element to 0 LOOP through array IF current element is greater than max_element SET max_element to current element END LOOP PRINT maximum element END
null
Design a die roll program in Java.
import java.util.Random; public class RollDie { public static void main(String[] args) { // creating instance of Random class Random rand = new Random(); // Generate random integers in range 0 to 6 int rand_int = rand.nextInt(6); // Print random integers System.out.println("The die shows : "+ (rand_int + 1)); } }
null
Design a python program to convert a given number of days into years, months, and days.
# convert days def convert_days(days): years = days // 365 months = (days % 365) // 30 days = (days % 365) % 30 return (years, months, days) # test days = 900 years, months, days = convert_days(days) print("Number of years =", years) print("Number of months =", months) print("Number of days =", days)
null
Develop an algorithm in Python to sort a list of numbers using merge sort.
list = [10, 7, 8, 9, 1, 5]
def mergeSort(arr): if len(arr) > 1: mid = len(arr)//2 left = arr[:mid] right = arr[mid:] mergeSort(left) mergeSort(right) i = 0 j = 0 k = 0 while i < len(left) and j < len(right): if left[i] < right[j]: a...
null
Create a Python function that takes a list of numbers and returns the sum of the odd numbers in the list.
[1, 2, 3, 4, 5]
def sumOdds(nums): total = 0 for num in nums: if num % 2 != 0: total += num return total nums = [1,2,3,4,5] sum_odds = sumOdds(nums) print(sum_odds) #output: 9
null
Apply the given CSS style to the HTML element.
<div>Hello World</div> css: font-weight: bold;
<div style="font-weight: bold;">Hello World</div>
null
Produce a regular expression pattern in Python that validates emails.
Not applicable
import re def validate_email(email): email_regex = r'^[\w\.-]+@[\w\.-]+\.\w{2,4}$' return re.match(email_regex, email) != None
[DE Wikipedia] Reiner Solenander Reiner Solenander (* 1524 in Büderich; † 5. Januar 1601 in Büderich), ursprünglich Reiner Gathmann, war Badearzt in Lucca und Leibarzt Wilhelms des Reichen in Düsseldorf. Leben Als Sohn einer angesehenen Büdericher Bürgerfamilie besuchte Reiner Gathmann die Weseler Lateinschule. Rektor...
null
null
null
null
Write a Python class to modify the case of the string
A String with the text: "Hello World"
class StringCaseModifier: def __init__(self, string): self.string = string def to_upper(self): return self.string.upper() def to_lower(self): return self.string.lower() def to_title(self): return self.string.title() if __name__ == '__main__': test_string = 'He...
null
Using C++, create a program to calculate the volume of a rectangular prism given the length, width and height.
""" Using C++, create a program to calculate the volume of a rectangular prism given the length, width and height. """ #include <iostream> int main() { double length, width, height; // Prompt for the dimensions std::cout << "Enter the length, width and height: "; std::cin >> length >> width >> height; // Calculate the ...
null
Create a Python program that takes in a list of email addresses as argument and stores them in a CSV.
""" Create a Python program that takes in a list of email addresses and stores them in a CSV. """ import csv def store_emails(emails): with open('emails.csv', 'w', newline='') as csvfile: writer = csv.writer(csvfile) for email in emails: writer.writerow([email]) if __name__ == '__main...
[EN Wikipedia] 1950–51 Norwegian 1. Divisjon season The 1950–51 Norwegian 1. Divisjon season was the 12th season of ice hockey in Norway. Eight teams participated in the league, and Furuset IF won the championship. Regular season External links Norwegian Ice Hockey Federation Nor Eliteserien (ice hockey) seasons 1950–...
null
null
null
null
Write a MySQL query to update the price of all items that cost more than $50 to $50.
UPDATE items SET price = 50 WHERE price > 50;
null
Write a regex expression to match the given input.
abbccd
^(a|b|c){2}d$
[DE Wikipedia] Wittmack Wittmack ist der Familienname folgender Personen: Karlfranz Schmidt-Wittmack (1914–1987), deutscher Politiker (CDU), MdB Ludewig Wittmack (1839–1929), deutscher Botaniker Lilian Wittmack, dänische Springreiterin Siehe auch: Wittmaack
null
null
null
null
Write a Python program to find out the common items from two given arrays.
arr1 = [1, 2, 3, 5, 7 ] arr2 = [2, 3, 5, 6, 7]
common_items = [] for item in arr1: if item in arr2: common_items.append(item) print(common_items) # Output: [2, 3, 5, 7]
null
Write an SQL query to update the salary of employee with Id 4 to 80000
UPDATE employees SET Salary = 80000 WHERE ID = 4;
null
Write a recursive version of the following code.
def factorial(n): result = 1 for i in range(1, n + 1): result *= i return result
def factorial(n): if n == 0: return 1 else: return n * factorial(n - 1)
null
Write a SQL query to find the name and occupation of all people older than 60.
SELECT name, occupation FROM people WHERE age > 60;
null
Write a query in MongoDB to find all the documents in the collection "Books".
db.Books.find({})
null
Write a code to generate a random password consisting of 8 characters with atleast one lowercase letter, one uppercase letter and one number.
import string import random def generate_password(): password_characters = string.ascii_letters + string.digits password = ''.join(random.choice(password_characters) for i in range(8)) if not any(char.islower() for char in password): password = password[:7] + random.choice(string.ascii_lowercase) if not any(char.isuppe...
null
Construct an API using Flask that returns an array of integers in response to a request
from flask import Flask, jsonify app = Flask(__name__) @app.route('/api/v1/get_data', methods=['GET']) def get_data(): data = [1, 2, 3, 4, 5] return jsonify(data) if __name__ == '__main__': app.run()