text stringlengths 141 2.89k ⌀ | instruction stringlengths 19 1.5k ⌀ | input stringlengths 0 800 ⌀ | output stringlengths 1 2.5k ⌀ |
|---|---|---|---|
null | Create a web application that displays a list of all available program languages and their features. | Not applicable | <html>
<head>
<title>Programming Languages</title>
</head>
<body>
<h1>Programming Languages</h1>
<ul>
<li><b>JavaScript</b> – Object-oriented, event-driven, and functional programming language</li>
<li><b>Python</b> – Object-oriented, interpreted, high-level programming language</li>
<li><b>C</b> – High-level,... |
[CS Wikipedia] Akustika
Akustika je rozsáhlý vědní obor, zabývající se vznikem zvukového vlnění, jeho šířením, vnímáním zvuku sluchem a přenosu prostorem až po vnímání lidskými smysly. Má celou řadu poddisciplín, např. hudební akustika zkoumá fyzikální základy hudby, hudebních nástrojů a prostorů, stavební akustika zv... | null | null | null |
null | Generate a code in Python to classify the gender of a given name. | def classify_gender(name):
genders = {
'male': ['john', 'peter', 'mark'],
'female': ['alice', 'anna', 'jane']
}
for key, names in genders.items():
if name in names:
return key
return 'unknown' | |
null | Explain why it is important to have exception handling | Exception handling is important for a program as it allows the program to gracefully handle any unexpected or erroneous conditions. This helps keep the program running by providing meaningful feedback and prompts to the user. It also helps reduce the risk of having some part of the program crashing due to an unforeseen... | |
null | Generate a correct python program to return the second biggest element in a given list. | [1, 5, 9, 4, 16, 11] | def second_biggest(lst):
max1 = 0
max2 = 0
for num in lst:
if num > max1:
max1 = num
elif num > max2:
max2 = num
return max2
second_largest_num = second_biggest([1, 5, 9, 4, 16, 11])
print(second_largest_num) |
null | Use an existing Python function to find the longest string in the following array. | arr = ["cat", "dog", "elephant", "squirrel", "moose" | max(arr, key=len) # returns "elephant" |
[CS Wikipedia] Jasmin Savoy Brown
Jasmin Savoy Brown (* 21. března 1994, Alameda, Kalifornie) je americká herečka, která se proslavila hlavně díky roli Evie v seriálu stanice HBO Pozůstalí a rolí Allison Adams v seriálu For the People. Životopis a kariéra Narodila se v Alamedě v Kalifornii, ale vyrůstala ve Springfiel... | null | null | null |
[DE Wikipedia] Felice Govean
Felice Govean (* 19. Dezember 1819 in Racconigi, Piemont; † 10. März 1898 in Alpignano bei Turin) war ein Italienischer Dramatiker und Publizist. Leben Felice Govean entstammte einem gräflichen Geschlecht, machte seine Studien in Turin und übernahm dann eine Stelle bei einer Feuerversicher... | null | null | null |
null | Write a C# function to generate all combinations of length n of a given array. | static void GenerateCombinations(int[] arr, int n) { int[] result = new int[n]; GenerateCombination(arr, 0, 0, result); } static void GenerateCombination(int[] arr, int start, int index, int[] result) { if (index == result.Length) { Console.WriteLine(String.Join(",", result)); return; } for (int i = start; i < arr.Leng... | |
null | Create a function in Python that takes two numbers as arguments and returns their average. | 2, 3 | def average(a, b):
return (a + b) / 2
print(average(2, 3)) |
null | Create a C# method to find the third common element in two arrays | arr1: [8, 15, 20, 7, 2] arr2: [5, 6, 7, 9, 8] | public int FindCommonElement(int[] arr1, int[] arr2) { HashSet<int> set = new HashSet<int>(); foreach (int item in arr1) { set.Add(item); } List<int> commons = new List<int>(); foreach (int item in arr2) { if (set.Contains(item)) commons.Add(item); } return commons.Count >= 3 ? commons[2] : -1; } |
null | Create a function in Python that takes a list of strings and returns a dictionary containing a count of how many times each string appears in the list. | ["foo", "bar", "foo", "baz", "foo"] | def count_words(words):
counted_words = {}
for word in words:
if word not in counted_words:
counted_words[word] = 1
else:
counted_words[word] += 1
return counted_words
words = ["foo", "bar", "foo", "baz", "foo"]
result = count_words(words)
print(result) |
null | Write a Haskell program to calculate the sum of list elements. | [2,3,7,9] | sumlist :: [Integer] -> Integer sumlist [] = 0 sumlist (x:xs) = x + sumlist xs -- Driver Code main = do print (sumlist [2,3,7,9]) -- Output: 21 |
null | Develop a program in Python to compute the median of three numbers. | def median(a, b, c):
if (a <= b <= c) or (c <= b <= a):
median = b
elif (b <= a <= c) or (c <= a <= b):
median = a
else:
median = c
return median | |
[EN Wikipedia] Torchyn
Torchyn (; ) is an urban-type settlement in Lutsk Raion, Volyn Oblast, western Ukraine. It is located on the banks of the Serna in the drainage basin of the Dnieper. Population: Economy Transportation The closed railway station is in Lutsk. The settlement is on Highway H22 connecting Lutsk and V... | null | null | null |
[HI Wikipedia] बासल-श्तात कैन्टन
बासल-श्तात कैन्टन (जर्मन व अंग्रेज़ी: Basel-Stadt) स्विट्ज़रलैंड के उत्तर में स्थित एक कैन्टन (प्रान्त से मिलता-जुलता प्रशासनिक विभाग) है। जर्मन भाषा में 'बासल-श्तात' का मतलब 'बासल शहर' है और यह कैन्टन बासल शहर और उसके इर्द-गिर्द के कुछ इलाक़ों को मिलाकर बनी हुई है। इसके विपरीत बासल-ला... | null | null | null |
null | Create a class in C++ with one public member and one private member. | class MyClass { public: int publicMember; private: int privateMember; }; | |
null | Create a program in Python that takes a string as an input and prints out all unique substrings in the input string. | abcabc | string = "abcabc"
# To store unique substring
list_unique_substrings = []
# Iterating through the length of string
for index_i in range(len(string)):
# Iterating through the range of index_i and string length
for index_j in range(index_i, len(string)):
# Slice the substring from index_i to index_j
... |
[CS Wikipedia] Plazma (rozcestník)
Plazma může být: fyzika plazma – ionizovaný plyn, čtvrté skupenství hmoty biologie krevní plazma – tekutá část krve plazmatická membrána (plazmalema) – cytoplazmatická membrána buněk plazmatické proteiny – bílkoviny obsažené v krevní plazmě protoplazma – živá hmota vyplňující vnitřní... | null | null | null |
null | Input a two-dimensional array and calculate the sum of each row. | arr = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] | def row_sum(arr): row_sum = [] for row in arr: sum = 0 for ele in row: sum += ele row_sum.append(sum) return row_sum |
[DE Wikipedia] Tabu & Love Film
Die TABU FILM GmbH ist eine Filmproduktionsgesellschaft für Pornofilme mit Sitz in Essen. Im Jahr 1968 gründete der deutsche Pionier der Pornografie, Charly Brown, die Firma Tabu & Love Film. Lange bevor andere Produzenten in Deutschland den Schritt in die Pornografie wagten, drehte Cha... | null | null | null |
null | Write a JavaScript code to create a function that checks if a given number is divisible by 2. | function isDivisibleBy2(num) { return num % 2 === 0; } | |
null | Generate a python program for validating a phone number. | Phone numbers should be in 10-digit format (no dashes, hyphens, etc.). | def valid_phone_number(phone):
phone = str(phone)
return len(phone) == 10 and phone.isdigit() |
[HI Wikipedia] वी. एस अच्युतानान्तन
वेलिक्ककतु शंकरन अच्युतानंदन (मलयालम: വേലിക്കകത്ത് ശങ്കരന് അച്യുതാനന്തന്) एक भारतीय राजनीतिज्ञ है। ओन्होंने २००६ से २०११ तक केरल के मुख्यमंत्री थे। वर्तमान में वे केरल विधानसभा में विपक्ष के नेता के रूप में कार्य करता हैं। अच्युतानंदन ने भारत की कम्युनिस्ट पार्टी (मार्क्सवादी) के ... | null | null | null |
null | Write a line of code to input 10 numbers from the user. | a = list(map(int, input("Enter 10 numbers: ").split())) | |
null | Write a Python script to filter a list of text strings by removing all strings that contain a certain substring. | word_list = ['hello', 'apple', 'this', 'is', 'a', 'word']
keyword = 'a' | filtered_list = [x for x in word_list if keyword not in x]
# filtered_list = ['hello', 'this', 'word'] |
null | Create a python program to evaluate an expression string and return the result. | "10 + 2 * 5 - 3" | def calculate(expression):
stack = []
for i in expression:
if i.isdigit():
stack.append(int(i))
else:
val1 = stack.pop()
val2 = stack.pop()
if i == '+':
result = val2 + val1
elif i == '-':
resu... |
null | Given two strings s1 and s2, find the number of times the characters in s2 are present in s1. | s1 = "Hello World", s2 = "o" | s1 = "Hello World" s2 = "o" def count_characters(s1, s2): count = 0 for c in s1: if c == s2: count += 1 return count print(count_characters(s1,s2)) |
null | Can you build an algorithm in Python that determines if a number is odd or even? | def is_odd(number):
if number % 2 == 0:
return False
else:
return True | |
null | In Python, how could you print a list from the last element to the first element? | for element in reversed(my_list): print(element) | |
null | Model a NoSQL database using CosmosDB | The database should store user posts, which consists of the post ID, content text, user ID and date of creation. | Azure Cosmos DB is a NoSQL database-as-a-service model that provides a schema-free data model and supports automatic indexing of all data. To model a posts database with CosmosDB, create a database and a container. Then create item in the container, each item should contain the fields "Post ID", "ContentText", "User ID... |
null | Provide the logic for sorting an array of strings alphabetically. | for i in range(len(arr)): for j in range(i + 1, len(arr)): if arr[i] > arr[j]: arr[i], arr[j] = arr[j], arr[i] | |
null | Create a class in Python containing attributes, methods and constructors | class MyClass:
def __init__(self, attr1, attr2):
self.attr1 = attr1
self.attr2 = attr2
def my_method(self):
# Do something
pass | |
null | Generate a correct python program to format a given string s so that the output pattern is as follows | Given String: "Hello--world--someone"
The output pattern is: "Hello world someone". | def format_string(s):
string_arr = s.split("--")
return ' '.join(string_arr) |
null | Write an algorithm for sorting an array in ascending order using the Bubble Sort technique. | [3, 7, 4, 1, 9] | // Start loop for i in range(length of array): // Start inner loop for j in range(i+1, length of array): // Compare elements and swap if needed if array[i] > array[j]: temp = array[i] array[i] = array[j] array[j] = temp // End inner loop // End loop // Result: array is now sorted in ascending order [1, 3, 4, 7, 9] |
null | Compress a string using Huffman coding in Python. | String: "aaabbcc" | def get_freq_list(s): # dictionaries are efficient for such a task freq_list = {} for char in s: if char in freq_list.keys(): freq_list[char] += 1 else: freq_list[char] = 1 return freq_list def create_huffman_tree(freq_list): # create a priority queue # to pop two minimum element each time priority_queue = [] for key i... |
null | Write a sql statement to retrieve the average salary of all employees | SELECT AVG(salary) FROM employees | |
null | Write a function in JavaScript that counts the number of characters in a sentence. | The quick brown fox | function characterCounter(str) { return str.length; } |
null | Generate a Python program that reads a line from the user and prints out the number of words in the line. | def count_words():
sentence = input("Please enter a sentence here: ")
num_words = len(sentence.split())
print("The sentence has", num_words, "words.")
count_words() | |
null | Create a program to output the items in a list that appear only once. | list = [50, 10, 20, 30, 10, 50, 44, 55, 44] | items_set = set(list) unique_items = [] for item in items_set: if list.count(item) == 1: unique_items.append(item) print("Unique items:",unique_items) |
[DE Wikipedia] Braunes Bergschaf
Das Braune Bergschaf ist eine Nutztierrasse, die von den früher in Tirol und Bayern beheimateten Steinschafen abstammt. Aus Überlieferungen von Hirten und Schäfern geht hervor, dass damals der Anteil von farbigen Steinschafen weitaus größer war als der weißen. Die Haltung der überwiege... | null | null | null |
null | Design a Python class that represents a taxi. | class Taxi:
def __init__(self, capacity, license_number):
self.capacity = capacity
self.license_number = license_number
self.passengers = []
def add_passenger(self, passenger):
if self.capacity > len(self.passengers):
self.passengers.append(passenger)
... | |
null | Generate a HTML page with 3 columns using Bootstrap. | <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Bootstrap Example</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Bootstrap --> <link href="css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div class="row"> <div class="col-md-4"> <!-- Your content goes here --> </d... | |
null | Modify the following code to compute the sum of squares of the numbers from k to n. | def sum(k, n): sum = 0 for i in range(k, n+1): sum += i return sum | def sum_squares(k, n): sum = 0 for i in range(k, n+1): sum += i**2 return sum |
null | Create an algorithm to find the minimum number of coins required to make a given amount in python. | amount = 12 | def minimum_coins_needed(amount):
denominations = [1, 2, 5, 10]
result = [0 for _ in range(amount+1)]
# Compute the result for amount = 0
result[0] = 0
# Iterate over all amount from 1 to desired
for i in range(1, amount+1):
# Initialize an inner loop to maximum value (amount)
... |
null | Write a python code to perform a three-way comparison of three numbers. | def three_way_comparison(num1, num2, num3):
if num1 > num2 and num1 > num3:
return 1
elif num2 > num1 and num2 > num3:
return 2
elif num3 > num1 and num3 > num2:
return 3 | |
null | Analyze a given Python code snippet and determine its type - a documentation, a code snippet, or a comment. | def f(x):
"""A simple function
that prints the argument"""
print(x) | Documentation |
null | Develop a Python algorithm to validate a given palindrome string. | "level" | def isPalindrome(s):
i = 0
j = len(s) - 1
while i < j:
if s[i] != s[j]:
return False
i += 1
j -= 1
return True
# Driver code
s = "level"
if isPalindrome(s):
print("Yes")
else:
print("No") |
null | Explain the process of linear search in a few sentences. | Linear search is a technique for searching for an element in a list by repeatedly checking every element until a match is found or the end of the list is reached. It is typically implemented as a loop, where each element is compared to the search key until a match is found, or until all the elements have been searched. | |
[HI Wikipedia] कमरा
कमरा, कक्ष या ख़ाना किसी घर या अन्य निर्मित ढाँचे के अन्दर के ऐसे भाग को कहते हैं जो अलग विभाजित कर दिया गया हो। यह विभाजन दीवारों, पर्दों या दरवाजों से किया गया हो सकता है। आमतौर पर कमरों के ऊपर छत भी डली हुई होती है, लेकिन यह ज़रूरी नहीं है। ऐतिहासिक रूप से कमरे मिनोआई सभ्यता के २२०० ईसापूर्व में... | null | null | null |
[CS Wikipedia] Magdalény Rettigové
Ulice Magdalény Rettigové na Novém Městě v Praze je krátká neprůchodná (slepá) ulice vycházející od Lazarské ulice směrem k Purkyňově ulici. Nazvána je podle české kuchařky a spisovatelky Magdaleny Dobromily Rettigové (1785-1845). V ulici, u domu Diamant, je bezbariérový vstup do sta... | null | null | null |
null | Generate a JavaScript function to return the average of two numbers | function avgTwoNums(num1, num2) { const average = (num1 + num2) / 2; return average; } | |
null | Create a function in Python to group data by a column and apply aggregate functions on each group. | df = pd.DataFrame({"A": ["foo", "foo", "foo", "foo", "foo","bar", "bar", "bar", "bar"],
"B": ["one", "one", "one", "two", "two","one", "one", "two", "two"],
"C": [1, 2, 3, 4, 5, 6, 7, 8, 9],
"D": [2, 3, 4, 5, 6, 7, 6, 8, 9]}) | group_by_column = df.groupby("B").agg({'C': 'sum', 'D': 'mean'}) |
null | Create a function to remove the second largest element in a given array. | arr = [5, 4, 2, 1, 3] | def remove_second_largest(arr): max_arr = max(arr) arr.remove(max_arr) return max(arr) |
null | Implement a sorting algorithm in Python that sorts a list of strings in descending order of length. | arr = ["Apple", "Banana", "Cat", "Elephant"] | def sort_by_length(arr):
for i in range(len(arr)):
for j in range(i + 1, len(arr)):
if len(arr[i]) < len(arr[j]):
arr[i], arr[j] = arr[j], arr[i]
return arr
print(sort_by_length(arr)) |
null | Write a function that exchanges the first and last elements of a list. | def exchange_first_last(lst): first_item = lst[0] last_item = lst[-1] lst[0] = last_item lst[-1] = first_item return lst | |
[HI Wikipedia] हैरी पॉटर
यह लेख हैरी पॉटर उपन्यास क्रम के बारे में है। हैरी पॉटर पात्र के लिए हैरी पॉटर (पात्र) देखें। हैरी पॉटर या हैरी पौटर (अंग्रेज़ी: Harry Potter) जे. के. रोलिंग द्वारा अंग्रेज़ी में रचित एक उपन्यास क्रम है। इसमें एक नई जादुई दुनिया का वर्णन है जिसमें अच्छे और बुरे जादूगर, जादू का विद्यालय, झाड़ू ... | null | null | null |
null | In Ruby, write a method to find the sum of two numbers from the given string. | String: “The sum of 4 and 8 is 12” | def sum_from_string(str) array = str.scan(/\d+/).map(&:to_i) sum = array[0] + array[1] return sum end sum_from_string("The sum of 4 and 8 is 12") # Output: 12 |
null | Write a CSS rule to set the text color of a page to red | body { color: red; } | |
[CS Wikipedia] Seznam dílů seriálu Smrtonosná zbraň
Toto je seznam dílů seriálu Smrtonosná zbraň. Dne 10. května 2019 byl seriál stanicí Fox po třech řadách zrušen. Přehled řad Seznam dílů První řada (2016–2017) Druhá řada (2017–2018) Třetí řada (2018–2019) Reference Externí odkazy Smrtonosná zbraň | null | null | null |
null | Write a JavaScript code to compare the values of two strings | if (string1 === string2) { console.log("The strings are equal.") } else { console.log("The strings are not equal.") } | |
null | Create a Python program to print out the elements of a list in reverse order. | mylist = [1, 2, 3, 4, 5] | # Creating a new reversed list
reversed_list = mylist[::-1]
# Iterating through the list and printing each element
for num in reversed_list:
print(num) |
null | Create a basic Python game that allows a user to guess a number from 1 to 10. The game should display appropriate messages based on the player's input. | Not applicable | # Game script
import random
# Welcome message
print("Welcome to the guessing game!")
# Generate a random number
target_number = random.randint(1, 10)
# Initialise variables and flags
guessed = False
attempts = 0
while not guessed:
attempts += 1
guess = int(input("Guess a number (1-10): "))
if guess < target_num... |
null | Write a Python program to create a tree structure in JSON for given input data. | {"name": "root", "children": [{"name": "a", "children": [{"name": "b", "children": []}]}]} | import json
data = {
'name': 'root',
'children': [
{
'name': 'a',
'children': [
{
'name': 'b',
'children': []
}
]
}
]
}
json_string = json.dumps(data, indent=4)
print(json_string)
#... |
[HI Wikipedia] लाग्रांजीय यांत्रिकी
लाग्रांजीय यांत्रिकी अथवा लाग्रांजियन यांत्रिकी स्थिर प्रक्रिया द्वारा हेमिल्टन विधि द्वारा चिरसम्मत यांत्रिकी का एक पुनःसूत्रिकरण है। वैचारिक ढांचा व्यापकीकृत निर्देशांक अवधारणा एवं शब्दावली यदि किसी कण पर बाह्य बल कार्य करते हैं तो न्यूटन के गति के नियमानुसार तीनों विमाओं के लिए त... | null | null | null |
null | What is the definition of polymorphism in programming? | Polymorphism in programming is a principle allowing the same code to be used for objects of different types, or for a given object to behave differently in different contexts. Polymorphism is an essential element of object-oriented programming, as it allows for code reusability, among other benefits. Polymorphism is ac... | |
[EN Wikipedia] Rancho Los Alamos
Rancho Los Álamos was a Mexican land grant in present-day Santa Barbara County, California given in 1839 by Governor Juan Alvarado to José Antonio de la Guerra, a son of José de la Guerra y Noriega. Los Álamos is Spanish for "the cottonwoods" and describes Frémont's Cottonwood (Populus... | null | null | null |
[DE Wikipedia] Abbas-Ali Soleimani
Abbas-Ali Soleimani (; * 25. Mai 1947 In Savādkuh, Mazandaran, Iran; gest. 26. April 2023 in Bābolsar, Mazandaran, Iran) war ein schiitischer Geistlicher aus dem Iran und auch ein Ayatollah. Er war Mitglied des Expertenrats. Leben Am 25. Mai 1947 kam Soleimani in einer religiösen Fam... | null | null | null |
null | Create a Swift function for checking if a number is even or odd. | func isEven(num: Int) -> Bool { return (num % 2) == 0 } | |
[HI Wikipedia] कालामी भाषा
कालामी को गावरी भाषा भी कहते हैं - इस से भिन्न गोवरो भाषा के लिए गोवरो भाषा का पन्ना देखिये कालामी (Kalami, ), जिसे कालाम कोहिस्तानी या गावरी (Gawri, ) भी कहते हैं, कोहिस्तानी शाखा की एक दार्दी भाषा है जो पाकिस्तान के ख़ैबर-पख़्तूनख़्वा प्रान्त के कोहिस्तान ज़िले बोली जाती है। श्रेणीकरण काल... | null | null | null |
null | Write a Python program to remove the duplicates from a given list of numbers while preserving the order of elements. | [1, 2, 3, 2, 1] | def remove_duplicates(lst):
new_list = []
for i in lst:
if i not in new_list:
new_list.append(i)
return new_list
print(remove_duplicates([1, 2, 3, 2, 1])) |
null | Format the output of a number to contain comma-separated thousands. | num = 323456789 | # Format the output of a number to contain comma-separated thousands def format_number(num): return '{:,}'.format(num) # Get the formatted output print(format_number(323456789)) # Output: 323,456,789 |
null | Write a Python program to calculate the letter grade of a given numerical grade. | def calculate_grade(score):
if score >= 90:
return "A"
elif score >= 80:
return "B"
elif score >= 70:
return "C"
elif score >= 60:
return "D"
else:
return "F"
result = calculate_grade(90)
print(result) | |
[EN Wikipedia] Ready reckoner
A ready reckoner is a printed book or table containing pre-calculated values, often multiples of given amounts. They were widely used in shops and by tradesmen before the advent of cheap electronic calculators, metric weights and measures and decimal currencies in the 1970s. Background Pr... | null | null | null |
null | Create a function that adds two inputs of type integers and returns the sum. | a = 8 b = 3 | def add(a, b): return a + b |
null | Design an algorithm in Python that sorts an unordered list of three numbers in increasing order. | List = [3, 1, 2] | def sort_list(input_list):
output_list = []
while input_list:
smallest = input_list[0]
for i in input_list:
if i < smallest:
smallest = i
output_list.append(smallest)
input_list.remove(smallest)
return output_list |
[HI Wikipedia] रगडगंज
रगड्गंज बाज़ार जिला गोण्डा से 18 किलोमीटर दूर स्थित है। यहां पर अनेक जाति एवम धर्म के लोग निवास करते है। इनके अन्दर काफी मेल जोल रहता है। यहां से 14 किलोमीटर दक्खिन दिशा की ओर बहुत ही विशालतम देव स्थान है। जो कि उत्तरी भवानी के नाम से प्रसिद्ध है। | null | null | null |
[HI Wikipedia] कृपानिवास
कृपानिवास रसिक रामोपासना के एक प्रमुख आचार्य। इनका जन्म १७५० ई. के आसपास दक्षिण भारत में हुआ था। इनके पिता का नाम सीतानिवास तथा माता का गुणशीला था। वे श्री रंग के उपासक थे। उन्होंने इन्हें बचपन ही में रामानुजीय वैष्णव संत आनंद विलास से दीक्षा दिलाई। पंद्रह वर्ष की अवस्था में इन्हें संसार से वि... | null | null | null |
null | Rewrite the following Python program to sort the numbers in an array in ascending order. | list = [5, 1, 0, 4, 7] | def sort(list): for i in range(len(list)-1): for j in range(0, len(list)-i-1): if list[j] > list[j+1] : list[j], list[j+1] = list[j+1], list[j] list = [5, 1, 0, 4, 7] sort(list) print ("Sorted list is:") print(list) |
null | Design a Python class to represent a user with fields name and age. | class User: def __init__(self, name, age): self.name = name self.age = age def get_name(self): return self.name def get_age(self): return self.age | |
null | Design a data structure in Python for a deck of cards. | class Card:
suits = ("Hearts", "Diamonds", "Spades", "Clubs")
values = ("A", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "J", "Q", "K")
def __init__(self, suit, value):
self.suit = suit
self.value = value
def __repr__(self):
return f"{self.value} of {se... | |
null | Develop a python program automate the process of generating a list of random numbers between 1 to 100. | import random
def generate_random_nums(n,min_val,max_val):
output = []
for i in range(n):
output.append(random.randint(min_val,max_val))
return output
if __name__ == '__main__':
n = 10
min_val = 1
max_val = 100
print(generate_random_nums(n,min_val,max_val)) | |
[EN Wikipedia] Amorbia emigratella
Amorbia emigratella, the Mexican leaf-roller, is a moth of the family Tortricidae. Although it was described from Hawaii (where it is found on Kauai, Oahu, Molokai, Maui and Hawaii), it is known to be a native of the southern United States, Mexico and Central America. It was first de... | null | null | null |
null | Create a Python program which performs basic math operations on user input numbers and prints the result. | Not applicable | # Function to add two numbers
def add(x, y):
return x + y
# Function to subtract two numbers
def subtract(x, y):
return x - y
# Function to multiply two numbers
def multiply(x, y):
return x * y
# Function to divide two numbers
def divide(x, y):
return x / y
# Take inputs from the user
num1 = int(input("Enter fi... |
null | Generate a Python code to implement the classic Tower of Hanoi problem. | def tower_of_hanoi(n, from_rod, to_rod, aux_rod):
if n == 1:
print("Move disk 1 from rod",from_rod,"to rod",to_rod)
return
tower_of_hanoi(n-1, from_rod, aux_rod, to_rod)
print("Move disk",n,"from rod",from_rod,"to rod",to_rod)
tower_of_hanoi(n-1, aux_rod, to_rod, from_rod) | |
null | Generate a Python function to print the Fibonacci series up to a given number. | def print_fibonacci(num):
a = 0
b = 1
print(a, end =' ')
print(b, end =' ')
for i in range(2,num):
c = a + b
a = b
b = c
print(c, end =' ') | |
null | Can you retrieve the item at index 3 from the following array? | int[] arr = {11, 30, 45, 19, 20, 60}; | int itemAtIndex3 = arr[3]; // itemAtIndex3 is equal to 19 |
null | Write a Python script to find the area of a triangle when three sides are given. | a = 3
b = 4
c = 5 | # calculate the semi-perimeter
s = ( a + b + c ) / 2
# calculate the area
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is %0.2f' %area)
// Output: The area of the triangle is 6.00 |
[EN Wikipedia] August 27
Events Pre-1600 410 – The sacking of Rome by the Visigoths ends after three days. 1172 – Henry the Young King and Margaret of France are crowned junior king and queen of England. 1232 – Shikken Hojo Yasutoki of the Kamakura shogunate promulgates the Goseibai Shikimoku, the first Japanese legal... | null | null | null |
null | Name a specific package that can be used to implement a REST API in Node.js | The Express.js package can be used to implement a REST API in Node.js. | |
[CS Wikipedia] Bílkova (Praha)
Bílkova ulice v dnešní podobě vznikla po asanaci Židovského města v roce 1893 spojením 3 částí ulic. Západní část se jmenovala “Masařská“ podle zdejších (židovských) masných krámů. Prostřední část ulice se jmenovala “Scheplesova“ podle zdejších lázní pana Scheplesa. Východní část ulice s... | null | null | null |
null | Create a function to calculate the maximum of two numbers. | def max_of_two(x, y): if x > y: return x else: return y | |
[HI Wikipedia] पर्माफ़्रोस्ट
भूविज्ञान में स्थायीतुषार या पर्माफ़्रोस्ट (permafrost) ऐसी धरती को बोलते हैं जिसमें मिट्टी लगातार कम-से-कम दो वर्षों तक पानी जमने के तापमान (यानि शुन्य सेंटीग्रेड) से कम तापमान पर रही हो। इस प्रकार की धरती में मौजूद पानी अक्सर मिटटी के साथ मिलकर उसे इतनी सख़्ती से जमा देता है कि मिटटी भी ... | null | null | null |
null | How can you sort a list of strings lexicographically in C++? | We can use the sort() method from the algorithm library to sort a list of strings lexicographically in C++. The syntax for this method is as follows: sort(listOfStrings.begin(), listOfStrings.end()); | |
null | Implement a basic calculator that can compute simple math expressions. | 9 * 2 | def calculate(expr): return eval(expr) |
null | Given a two dimensional array, write a Python program to print the second diagonal of the array. | my_array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] | my_array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] # A function to print second diagonal of # given array def print_second_diagonal(arr): # Find length of given array n = len(arr) # Traverse second diagonal for i in range(0, n): print(arr[i][n-1-i], end = " ") # Driver code print_second_diagonal(my_array) # Output: 3 6 9 |
[EN Wikipedia] Cēsu Alus
Cēsu Alus is a brewery and alcohol beverage producer in Cēsis, Latvia. As the roots of the brewery dates back in 1590, Cēsu Alus is considered to be the oldest brewery in Baltic and Nordic countries. Cēsu alus is the largest brewery producing beer in Latvia. In year 2018 Cēsu alus produced 64%... | null | null | null |
null | Could you create a function in Python for reaching an element in a given list with a specific index? | [2, 3, 5, 7, 11], index = 3 | def get_element(lst, index):
return lst[index] |
null | Using a switch-case statement, calculate the grade for the student using the percentage in the input. | Student percentage: 80 | switch(percentage) { case (percentage >= 90): grade = 'A'; break; case (percentage >= 80): grade = 'B'; break; case (percentage >= 70): grade = 'C'; break; case (percentage >= 60): grade = 'D'; break; case (percentage < 60): grade = 'F'; break; default: grade = 'Invalid'; break; } |
null | Write a code in Ruby to convert an array of integers into a string. | The given array is [1,2,3,4,5]. | def convert_integers_to_string(array) array.map(&:to_s).join(', ') end array = [1,2,3,4,5] puts convert_integers_to_string(array) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.