text
stringlengths
141
2.89k
⌀
instruction
stringlengths
19
1.5k
⌀
input
stringlengths
0
800
⌀
output
stringlengths
1
2.5k
⌀
null
Classify the following sentence as offensive or non-offensive.
Sentence: Your work is terrible!
Offensive.
null
What is the command line to create a tar archive in Linux?
The command line to create a tar archive in Linux is "tar -cvf <archive name>.tar <target directory>". This will create a tar archive with the given name from the provided target directory.
[EN Wikipedia] Hurricane Julia (2010) Hurricane Julia was the easternmost Category 4 hurricane recorded in the Atlantic basin since reliable satellite observations became available. The twelfth tropical cyclone, fifth hurricane and fourth major hurricane of the 2010 Atlantic hurricane season, Julia rapidly developed o...
null
null
null
null
Write a Python program to format a number with leading zeros.
def leading_zeros(num, zeros=6): return str(num).zfill(zeros)
null
Create a function to output a nested dictionary from a given list of keys and values.
list_keys = ["a", "b", "c"] list_vals = [1, 2, 3]
def dictionary(list_keys, list_vals): dict1 = dict(zip(list_keys, list_vals)) return dict1 final_dict = dictionary(list_keys, list_vals) print("Final dictionary:", final_dict)
null
Provide a Python program to find the average number of elements in the nested list.
[[1, 2, 3], [4, 5], [6, 7, 8, 9]]
def avg_elements(list_of_lists): total_elements = 0 for sublist in list_of_lists: total_elements += len(sublist) return total_elements / len(list_of_lists)
null
How do you use the built-in function filter() in Python?
The filter() function in Python takes a function and an iterable as input arguments. The filter() function filters out elements from the given iterable (for example, a list) that don't satisfy the given condition determined by the function. It returns an iterator containing the filtered elements. Syntax: filter(functio...
[EN Wikipedia] Mircea Ştefănescu Mircea Ştefănescu (born 2 December 1936) is a Romanian water polo player. He competed at the 1960 Summer Olympics and the 1964 Summer Olympics. See also Romania men's Olympic water polo team records and statistics List of men's Olympic water polo tournament goalkeepers References Exter...
null
null
null
null
Given two strings, write a Python code to delete all occurrences of the second string from the first string.
str1 = "abcabcabcabcabcabcabcabcabcabc" str2 = "abc"
def delete_occurrences(str1, str2): return str1.replace(str2, '')
[EN Wikipedia] Graham Smith (priest) Graham Charles Morell Smith (born 7 November 1947) is a priest in the Church of England. Smith was educated at Whitgift School and Durham University. He was ordained in 1977 and began his ministry as a curate at All Saints', Tooting Graveney. Following this he was vicar of St Paul'...
null
null
null
null
Write a Java program to take in 3 strings and combine them into one.
string1 = "hello" string2 = "world" string3 = "!"
public class CombineStrings { public static void main(String[] args) { String string1 = "hello"; String string2 = "world"; String string3 = "!"; String output = string1 + string2 + string3 ; System.out.println(output); //hello world! } }
null
Write a function that takes three integers and returns the maximum of the three.
-2, 5, 7
def max_of_three(x, y, z): return max(x, y, z) print(max_of_three(-2, 5, 7)) # Output: 7
null
Assign the values of list_2 to the same positions of list_1.
list_1 = [1, 2, 5, 8] list_2 = [3, 6, 9, 12]
list_1[0] = 3 list_1[1] = 6 list_1[2] = 9 list_1[3] = 12
[EN Wikipedia] Kimberley Leggett Kimberley Leggett (born 23 March 1993) is a Malaysian British beauty pageant titleholder who was crowned Miss Universe Malaysia 2012. She represented Malaysia at Miss Universe 2012. Personal life Leggett was born and raised in Tanjung Bungah, Penang, Malaysia to Jillian Estrop and Step...
null
null
null
null
Develop a Python program to send a mail notification when a certain event is triggered.
import smtplib # Chnage this variable when the event is triggered message_sent = False if not message_sent: # Replace sender_email and receiver_email with valid email sender_email = "SENDER EMAIL" receiver_email = "RECEIVER EMAIL" message = "The event has been triggered." server = smtplib.SMT...
null
Write a Python program using NumPy to generate a random array of 10 values between 0 and 1.
Not applicable
import numpy as np # Generate an array of 10 random values between 0 and 1 array = np.random.random(10) print(array)
null
Generate a code to transform the list of strings into the upper case.
list = ['apple', 'banana', 'cherry']
list = ['apple', 'banana', 'cherry'] def transform_list(list): upper_list = [i.upper() for i in list] return upper_list print(transform_list(list))
[CS Wikipedia] Římskokatolická farnost Týn nad Vltavou Římskokatolická farnost Týn nad Vltavou je územním společenstvím římských katolíků v rámci vikariátu České Budějovice - venkov českobudějovické diecéze. O farnosti Historie Týn nad Vltavou byl původně součástí majetků pražského biskupství a místní hrad sloužil jak...
null
null
null
null
Create a search engine in Python that searches the web for relevant information on a given topic.
import requests # Perform a google search and returns the first page of results def search(query): # Use a custom user-agent to avoid being blocked by Google headers = { 'User-Agent': 'MySearchEngine/1.0' } # Build the query string query_string = { 'q': query } # Send the ...
null
Create a new dictionary in Python with the given keys and values.
Keys: A, B Values: 1, 2
d = {'A': 1, 'B': 2}
null
To use the Vlcclient class for communication with VLC player, follow these steps: 1. Import the necessary modules: threading, time, urllib, player.client.baseplayer, vlc.Meta, vlc.EventType, queue, and util.fileutil. 2. Create an instance of the Vlcclient class. 3. Call the start_client() method to start the threads...
# Copyright 2016-2021 Peppy Player peppy.player@gmail.com # # This file is part of Peppy Player. # # Peppy Player 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 3 of the License, or # (at you...
[CS Wikipedia] Kruhová rychlost Kruhová rychlost (u Země při povrchu jde o 1. kosmickou rychlost) je rychlost, kterou se pohybuje po kruhové dráze kolem centrálního tělesa v dané výši těleso zanedbatelně malé hmotnosti. Velikost kruhové rychlosti závisí na hmotnosti M (respektive gravitačním parametru ) centrálního tě...
null
null
null
null
Write a SQL query to retrieve the total amount of purchase each customer has made.
Table:Customer_orders |userid|product |purchase_price| |------|--------|--------------| |1 |shoes |50 | |2 |socks |30 | |1 |pants |20 |
SELECT userid, SUM(purchase_price) as total_purchase FROM Customer_orders GROUP BY userid;
null
Create a python script to display a grid pattern.
def printgrid(rows, columns): for i in range(1, rows+1): for j in range(1, columns+1): print("*", end=" ") print("\r") printgrid(4, 4)
null
Design a program to compute the median of 3 integers.
def median(a,b,c): if a >= b: if c >= a: return a elif b >= c: return b else: return c else: if c >= b: return b elif a >= c: return a else: return c
[DE Wikipedia] Hohe Flum Der oder die Hohe Flum ist mit die höchste Erhebung des Gebirgszugs Dinkelberg. Er liegt zwischen den Ortschaften Wiechs und Nordschwaben im baden-württembergischen Landkreis Lörrach. Auf dem Berg steht der Aussichtsturm Hohe Flum. Geographie Lage Der Hohe Flum befindet sich östlich des Zentru...
null
null
null
[HI Wikipedia] बिभा इंटरनॅशनल स्कूल बिभा इंटरनेशनल स्कूल (English - Bivha International School), जिसे बिभा अंतरराष्ट्रीय चिकित्सा एंव विज्ञान विद्यालय के नाम से भी जाना जाता हैं। ये अंतरराष्ट्रीय स्तर की नामचीन संस्था हैं, जिसे डाँ पमल(Dr. Pamal) ने सुपौल जिलाके सिमराही बाजार नामक शहर में 8 मई २०११ को स्थापित किया गया...
null
null
null
[HI Wikipedia] मीन सॉस मीन सॉस, एक पीले रंग का तरल है जिसे, मछली और समुद्री नमक के किण्वन से प्राप्त किया जाता है। इसका प्रयोग विभिन्न व्यंजनों में एक मसाले के रूप में प्रयोग किया जाता है। मीन सॉस, दक्षिण पूर्व एशिया और पूर्व एशिया के तटीय क्षेत्रों की कई संस्कृतियों के भोजन का एक मुख्य घटक है और मुख्यत: थाई, कंबोडिया...
null
null
null
null
Create a Python program to generate a random password that satisfies a given set of criteria.
A password should contain at least one upper case character, one lower case character, one special character and one number.
import random import string def generate_password(): # generate a random string of 8 characters characters = string.ascii_letters + string.digits + '!@#$%^&*' password = ''.join(random.choice(characters) for i in range(8)) # check if the password satisfies all criteria while not satisfy_crit...
null
Write a function in the Python language to convert a string to a list.
my_string = "Welcome to the world of GPT models"
def string_to_list(my_string): return my_string.split()
null
Create a PHP function to trim a string and remove all leading and trailing whitespace.
$string = " Hello World ";
function trimString($string) { return preg_replace('/^\s+|\s+$/', '', $string); } //calling the function trimString($string); //Returns "Hello World"
null
Compose a JavaScript code to sum all odd numbers in the range
From 1 to 10,
let sum = 0; for (let i = 1; i <= 10; i++) { if (i % 2 != 0) { sum += i; } } console.log(sum); //25
null
Construct a code to find the sum of a series of numbers entered by the user using Python.
total = 0 count = 0 while True: user_input = int(input("Enter an integer (enter 0 to stop): ")) if user_input == 0: break else: total += user_input count += 1 print("The sum of", count, "numbers is", total)
null
Construct a declaration in Java to store the coordinates of a point in 3D space.
public class point3D { int x; int y; int z; }
null
Create an HTML web page that has a "Hello World!" heading.
<!doctype html> <html> <head> <title>Hello World</title> </head> <body> <h1>Hello World!</h1> </body> </html>
[EN Wikipedia] Doppler fetal monitor A Doppler fetal monitor is a hand-held ultrasound transducer used to detect the fetal heartbeat for prenatal care. It uses the Doppler effect to provide an audible simulation of the heart beat. Some models also display the heart rate in beats per minute (BPM). Use of this monitor i...
null
null
null
null
Write a function in Python for printing a given 2D array.
arr = [[1,2,3], [4,5,6], [7,8,9]]
def print_2D_array(arr): for row in arr: for element in row: print(element,end=" ") print() print_2D_array(arr)
null
Create a SQL query that lists all entries from a table that have a given parameter in the distinct column.
Table: employee Parameter: name
SELECT DISTINCT name FROM employee;
[EN Wikipedia] Neohermenias thalassitis Neohermenias thalassitis is a moth of the family Tortricidae. It is found in Thailand and Java. References Moths described in 1910 Eucosmini
null
null
null
[EN Wikipedia] Éric Delaunay Éric Delaunay (born 4 December 1987) is a French sports shooter. He competed in the men's skeet event at the 2016 Summer Olympics. He qualified to represent France at the 2020 Summer Olympics. References External links 1987 births Living people French male sport shooters Olympic shooters f...
null
null
null
[DE Wikipedia] ʿAbdul-Bahāʾ ʿAbdul-Bahāʾ (; geboren 23. Mai 1844 in Teheran, Iran; gestorben 28. November 1921 in Haifa, Israel, damals Völkerbundsmandat für Palästina) war der Sohn des Religionsstifters Bahāʾullāh. Nach dessen Tod wurde er das religiöse Oberhaupt der Bahāʾī-Gemeinde und Ausleger der Heiligen Schrifte...
null
null
null
null
How can you pass multiple parameters in a function?
You can pass multiple parameters in a function by using either argument lists, or by using objects or arrays to group multiple parameters together.
null
Develop a Python program to sort a given array of numbers in ascending order by selection sort.
Sort the following array in ascending order: [2, -3, 1, 10, 0]
def selection_sort(arr): # Iterate through array for i in range(0, len(arr)-1): # Find the minimum element in the unsorted subarray min_index = i for j in range(i+1, len(arr)): if arr[min_index] > arr[j]: min_index = j # Swap the found minimum element with the first ...
null
Explain what a Python dictionary is.
""" Explain what a Python dictionary is. """ A Python dictionary is a collection of key-value pairs. Each key is associated with a single value, and each key is unique. Dictionaries are mutable, meaning that their values can be changed after they are created. Dictionaries are commonly used for storing data in a structu...
null
Create a SQL query to fetch the data from the following tables.
Table A id name 1 John 2 Mary Table B id age 1 20 2 25
SELECT a.name, b.age FROM tableA a INNER JOIN tableB b ON a.id = b.id;
null
Create a set of python functions and classes to build a shell command processor.
class Command(): def __init__(self, command_name, params): self.command_name = command_name self.params = params def is_valid_command(self): # Your code here pass def process_command(command): # Your code here pass
null
Create a function to encrypt and decrypt a string using a Caesar cipher in Python.
Not applicable
def encrypt(string, shift): encrypted_string = "" for char in string: if char == ' ': encrypted_string += char else: encrypted_ascii = ord(char) + shift if encrypted_ascii > ord('z'): encrypted_ascii -= 26 encrypted_string += chr(...
null
Develop a Python program to calculate the sum of two integers provided as command line arguments.
Not applicable
import sys # Get the command line arguments a = int(sys.argv[1]) b = int(sys.argv[2]) # Calculate the sum sum = a + b # Print the result print(sum)
null
Build a Python script to remove all punctuation from a given string.
"This is a cool string!"
import string input_str = "This is a cool string!" punctuation_removed = input_str.translate(str.maketrans('', '', string.punctuation)) print(punctuation_removed)
[HI Wikipedia] मुकेश (गायक) मुकेश चंद माथुर जुलाई २२, १९२३, दिल्ली, भारत - अगस्त २७, १९७६, लोकप्रिय तौर पर सिर्फ मुकेश के नाम से जाने वाले, हिन्दी सिनेमा के एक प्रमुख पार्श्व गायक थे। मुकेश की आवाज बहुत मधुर थी लेकिन उनके एक दूर के संबंधी मोतीलाल ने उन्हें तब पहचाना जब उन्होंने उसे अपनी बहन की शादी में गाते हुए सुना। ...
null
null
null
[CS Wikipedia] Farní sbor Českobratrské církve evangelické v Praze 10 – Uhříněves Farní sbor Českobratrské církve evangelické v Praze 10 – Uhříněves je sborem Českobratrské církve evangelické v Praze. Sbor spadá pod Pražský seniorát. Využívá evangelický kostel na uhříněveském Husově náměstí. Sbor byl ustaven jako samo...
null
null
null
null
Create an algorithm in C# with a time complexity of O(n2).
public static void printAllPairs(int[] array, int n) { for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) Console.Write("(" + array[i] + ", " + array[j] +") "); }
null
Create a python program to read an integer from the keyboard and print a message saying whether the number is even or odd?
def read_int_even_odd(): number = int(input("Enter an integer: ")) if number % 2 == 0: print("The number is even") else: print("The number is odd") read_int_even_odd()
[DE Wikipedia] Tito Larriva Humberto Lorenzo Rodriquez Larriva (* 1953 in Ciudad Juárez, Chihuahua, Mexiko) ist ein mexikanischer Sänger, Musiker und Schauspieler. Leben Larriva wuchs auf in Fairbanks, Alaska und El Paso, Texas. Als Kind lernte er, Flöte und Geige zu spielen. Mitte der 1970er-Jahre zog er nach Los Ang...
null
null
null
[CS Wikipedia] Palembang P2 Palembang P2 či Palembang II (též jenom P2, P.2, P II nebo Gloembang a Karangendah) bylo utajované vojenské letiště vybudované Nizozemci asi 32 mil (asi 51 km) jihozápadně od dnešního Palembangu na Sumatře a používané za druhé světové války. Jeho poloha je uváděna jako nebo . Dnes je letišt...
null
null
null
null
Make a Swift program to print out the first three characters of a given string.
String word = "Hello";
import Foundation let word = "Hello" let characters = word.prefix(3) print(characters)
null
Analyze the following modified code and explain what the modified code does
int x = 10; if (x == 10) x = x + 10; else x = x - 10;
The modified code checks if the value of the variable x is equal to 10. If it is, it adds 10 to x, otherwise it subtracts 10. So the value of x will now be 20 if it was 10 initially, or 0 if it was not.
null
Write a factorial program without using the inbuilt factorial function in Python.
def factorial(n): if n == 0: return 1 else: return n * factorial(n-1)
null
Create a Python program which takes a list of words as input, and prints out the frequent words.
Words: ["python", "is", "a", "programming", "language"]
from collections import Counter words = ["python", "is", "a", "programming", "language"] word_count = Counter(words) for k,v in word_count.items(): print(k,v) # To get the most frequent word most_freq_word = max(word_count, key=word_count.get) print("Most frequent word is:", most_freq_word)
[CS Wikipedia] Farní sbor Českobratrské církve evangelické v Praze 10 – Vršovice Farní sbor Českobratrské církve evangelické v Praze 10 - Vršovice je sborem Českobratrské církve evangelické v Praze. Sbor spadá pod Pražský seniorát. Sbor byl ustaven jako samostatný roku 1951. Farářem sboru je Matěj Opočenský, kurátorem...
null
null
null
null
Suggest a completion for the following Python code to sort a given list of dictionaries by a given key.
my_list = [{'name': 'Bob', 'age': 20}, {'name': 'Alice', 'age': 10}]
def sort_dicts(my_list, key): return sorted(my_list, key=lambda x: x[key]) # Main if __name__ == "__main__": my_list = [{'name': 'Bob', 'age': 20}, {'name': 'Alice', 'age': 10}] key = 'age' print(sort_dicts(my_list, key)) # [{'name': 'Alice', 'age': 10}, {'name': 'Bob', 'age': 20}]
null
Create a function in SQL to return the average of all values in a column.
SELECT AVG(column_name) FROM table_name;
null
Assume that we have an array of integers. Create code to input the array and output the sum of all the elements of the array.
arr = [1, 2, 3, 4, 5]
def calculate_sum(arr): """Calculates sum of all elements in the given array""" total = 0 for num in arr: total += num return total if __name__ == '__main__': arr = [1, 2, 3, 4, 5] print(calculate_sum(arr))
[EN Wikipedia] Francis Oats Francis Oats (29 October 1848 – 1 September 1918) was a Cornish miner who became chairman of De Beers diamond company. He made extensive investments in the Cornish tin mining industry, which collapsed after he had died. He is known for Porthledden, a mansion he built at the tip of Cornwall....
null
null
null
null
Write a JS code that returns the items in an alphabetical order.
let items = ["Cat", "Dog", "Elephant", "Rabbit", "Fox"]
let items = ["Cat", "Dog", "Elephant", "Rabbit", "Fox"] function sortAlphabetically(items) { return items.sort(); } let result = sortAlphabetically(items); console.log(result);
null
Make a POST request to the same server and download the response content
import requests url = 'http://example.com/' data = {'key': 'value'} response = requests.post(url, data=data) #Download response content with open('response_content.txt', 'wb') as f: f.write(response.content)
[DE Wikipedia] Schulmuseum Steinhorst Das Schulmuseum Steinhorst liegt im Heideort Steinhorst im Landkreis Gifhorn in Niedersachsen und ist Teil der Museen des Landkreises Gifhorn und damit der Bildungs- und Kultur gGmbH des Landkreises Gifhorn. Über das Museum Das Schulmuseum Steinhorst befindet sich im Gebäudeensemb...
null
null
null
null
Generate a SQL command to update the salary by 5% for all the employees.
UPDATE employees SET salary = salary * 1.05;
null
Create a CSS style to make all headings (h1, h2, h3, h4, h5, h6) bold and blue.
h1, h2, h3, h4, h5, h6{ font-weight: bold; color: blue; }
null
Find the maximum value from a Python dictionary.
sample_dict = {'a': 10, 'b': 20, 'c': 40, 'd': 30}
def find_max(sample_dict): max_val = 0 for key, val in sample_dict.items(): if val > max_val: max_val = val return max_val
[DE Wikipedia] Pfadicorps Patria Bern Das Pfadicorps Patria Bern ist ein Stadtberner Pfadfinder-Korps, das am 13. Februar 1913 gegründet wurde. Das Mitteilungsorgan des Pfadicorps Patria heisst Hallo und erscheint seit 1924 vierteljährlich. Geschichte Der Verein wurde 1913 in Bern als Pfadfinderabteilung Patria von Wa...
null
null
null
null
Create a program that takes in an array of integers as input and returns a sorted array in ascending order.
[7, 3, 5, 9, 11, 10]
def sort_ints(arr): return sorted(arr) my_list = [7, 3, 5, 9, 11, 10] print(sort_ints(my_list)) #Output: [3, 5, 7, 9, 10, 11]
null
Create a Python program to capture the data from a web page.
https://www.example.com/
import requests import lxml.html as lh url = 'https://www.example.com/' page = requests.get(url) doc = lh.fromstring(page.content) # parse and extract data from webpage data = doc.xpath('//p/text()')
null
Write a simple script in JavaScript to reverse a string.
text = “hello world”
function reverseString(text) { return text.split("").reverse().join(""); } console.log(reverseString(text));
null
Calculate the distance between two points using Pythagoras theorem.
Point A: (3, 4) Point B: (7, 8)
distance = sqrt((7-3)^2 + (8-4)^2) = sqrt(16 + 16) = sqrt(32) = 5.657
null
Write a web crawler in Python to collect job postings from a list of job boards.
Job Boards: 1. Monster.com 2. LinkedIn.com 3. Stack Overflow
import requests import bs4 import lxml job_boards = ['Monster.com', 'LinkedIn.com', 'Stack Overflow'] for board in job_boards: # Create a request object for the job board url r = requests.get(board) # Create a BeautifulSoup object from the response soup = bs4.BeautifulSoup(r.content, 'lxml') # Get all job post...
null
Given a JSON object, code a JavaScript function to convert the object into a query string.
let obj = { name: 'John', age: 25, job: 'developer' }
function jsonToQueryString(jsonObject) { let queryString = ''; for(let key in jsonObject) { queryString += key + '=' + jsonObject[key] + '&'; } return queryString.substring(0, queryString.length-1); } console.log(jsonToQueryString(obj)); // prints "name=John&age=25&job=developer"
null
Write a SQL query to select the names of all the students from the table "students".
SELECT name FROM students;
null
Generate an HTML snippet for a basic two-column layout.
<div class="container"> <div class="column"> <!-- Your left column content --> </div> <div class="column"> <!-- Your right column content --> </div> </div>
[EN Wikipedia] Joachim (surname) Joachim is a Germanic surname, ultimately derived from the Biblical king Jehoiakim. Pronunciation varies, and may be wa-keem' or jo'-akim. People with this surname Amalie Joachim (1839–1899), Austrian-German contralto and voice teacher, wife of Joseph Attila Joachim (1923–1947), Hungar...
null
null
null
null
Create a program to sum numbers in a given range m to n inclusive.
m = 4, n = 8
def sum_in_range(m, n): sum = 0 for i in range(m, n+1): sum+=i return sum
[CS Wikipedia] Benoît David Benoît David (* 19. dubna 1966 Montreal) je kanadský progressive rockový zpěvák, v letech 2008 až 2012 člen skupiny Yes. David vystupoval se skupinou Mystery od 1999–2013, a objevil se na jejich albech Beneath the Veil of Winter's Face (2007), One Among the Living (2010) a The World is a Ga...
null
null
null
null
Edit the given sql query to return all employee details having age greater than 30
SELECT * FROM employees;
SELECT * FROM employees WHERE age > 30;
null
Create a Python program for constructing a tree from a given inorder and preorder traversals.
Preorder Traversal: A, B, E, K, C, F, G, D Inorder Traversal: E, B, K, A, F, C, D, G
class Node: def __init__(self, data): self.data = data self.left = None self.right = None def construct_tree(preorder, inorder): if not preorder or not inorder: return None # first element of preorder is the root root = Node(preorder[0]) # get index of root in inorder idx = inorder.index(root.data) # lef...
null
Write a shell script to prompt a user for their name and display a personalized message.
#!/bin/bash read -p "Enter your name: " name echo "Hello $name, welcome to our website!"
null
Write an Algorithm in Python that takes in a comma-separated string of numbers and returns the sum of the numbers.
'1,2,3'
def sumString(s): nums = s.split(',') total = 0 for num in nums: total += int(num) return total
null
Create a Python script to generate a random password with a length of 8 characters that includes both uppercase and lowercase letters.
import string import random length = 8 alphabet = string.ascii_letters + string.digits password = ''.join(random.choice(alphabet) for i in range(length)) print("Generated password:", password)
null
Formulate a linear programming problem in Python to minimize a given cost function.
import pulp # Declare the problem prob = pulp.LpProblem("Cost Minimization Problem", pulp.LpMinimize) # Define the decision variables x = pulp.LpVariable("x", lowBound = 0) y = pulp.LpVariable("y", lowBound = 0) # Define the objective function prob += 4 * x + 5 * y # Define the constraints pro...
null
Identify any type error that is present in the following code.
def sum_of_values(num_list): total = 0 for value in num_list: total += value return total/len(num_list) square_value = sum_of_values(5)
Type error: The function sum_of_values() takes a list as an argument, but the argument provided is an integer (5).
null
Your job is to generate random numbers within a given range.
min = 20, max = 40
function getRandomNumber(min, max){ return Math.floor(Math.random() * (max - min + 1)) + min; } console.log(getRandomNumber(min, max));
[CS Wikipedia] Elektrické napětí Elektrické napětí je jedna ze základních veličin při studiu a využívání elektřiny. Napětí jako rozdíl potenciálů mezi dvěma body může způsobit elektrický proud a v analogii s kapalinou odpovídá rozdílu tlaků mezi dvěma body potrubí. Definuje se jako rozdíl potenciálů mezi dvěma body el...
null
null
null
null
Write a JavaScript function that takes an array of numbers and a function as arguments and returns an array with the same numbers as the input, but sorted in ascending order.
[2, 4, 3, 1]
function sortArrayAsc(arr, func) { return arr.sort(func); } function compareNumbers(a, b) { return a - b; }
null
Write a regex pattern to extract all words containing the letter 'a' from a given string
import re def extract_words(string): pattern = r'\b\w*a\w*\b' words = re.findall(pattern, string) return words
[DE Wikipedia] Behindertenrecht Das Behindertenrecht ist ein juristisches Querschnittsgebiet, das die Rechtsstellung von Menschen mit Behinderung betrifft. Es erstreckt sich insbesondere auf Regelungen im Sozial-, Arbeits- und Steuerrecht sowie auf gesetzliche Verpflichtungen zur Gleichstellung und Barrierefreiheit. I...
null
null
null
null
Find and list all the prime numbers between 0-100
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97.
null
Create a Python program to store prices for grocery items in a dictionary and write a function to calculate the total cost of the items.
groceries = {'apple': 3.99, 'banana': 2.99, 'milk': 5.99, 'bread': 3.50}
groceries = {'apple': 3.99, 'banana': 2.99, 'milk': 5.99, 'bread': 3.50} def total_cost(groceries): total = 0.0 for key in groceries: total += groceries[key] return total total_cost = total_cost(groceries) print(f'The total cost of all groceries is ${total_cost}.')
[HI Wikipedia] लिद्दर नदी लिद्दर नदी (Lidder River), जिसका मूल संस्कृत नाम लम्बोदरी नदी (Lambodari River) था, भारत के जम्मू व कश्मीर राज्य की कश्मीर घाटी में बहने वाली एक ७३ किमी लम्बी नदी है। सिन्द नदी के बाद यह झेलम नदी की दूसरी सबसे बड़ी उपनदी है। नामोत्पत्ति लिद्दर नदी का प्राचीन मूल नाम "लम्बोदरी नदी" था, और गणेश...
null
null
null
null
Generate a valid Python expression that multiplies the given numbers.
3 and 4
3 * 4
null
Change the code provided in the input so that it is compatible with Python version 3.
print "Hello World"
print("Hello World")
null
Compute the nearest prime number less than the given number using a python program.
173
def nearest_prime(num): if num <= 2: return -1 for i in range(num-1,2,-1): for j in range(2,i): if i % j == 0: break else: return i print(nearest_prime(173))