text
stringlengths
141
2.89k
⌀
instruction
stringlengths
19
1.5k
⌀
input
stringlengths
0
800
⌀
output
stringlengths
1
2.5k
⌀
null
Create a for loop to iterate through a given collection and print out an index for each element.
[5, 10, 15, 20]
for i, element in enumerate(collection): print(i, element) // Output 0 5 1 10 2 15 3 20
[EN Wikipedia] Lights Come Down Lights Come Down is the third EP released by Christian rock band, High Flight Society. It is also the band's final released work. It was released on iTunes under the label, "Caliber Recordings". Track listing Personnel Jason Wilkes – lead vocals, rhythm guitar Michael Packer – backing v...
null
null
null
null
Write a JavaScript Object that contains employee data such as name, age and contact number.
let employeeDetails = { name: "John Smith", age: 26, contactNumber: "123-456-7890" };
null
Transform the following array into an HTML unordered list.
const veggies = ["Lettuce", "Carrot", "Cucumber"]
<ul> <li>Lettuce</li> <li>Carrot</li> <li>Cucumber</li> </ul>
null
Write an R script that performs linear regression to predict a response variable.
# load the data data <- read.csv("data.csv") # fit the model model <- lm(formula = response ~ predictor, data = data) # view the results summary(model)
null
Create a Python code snippet to separate colored objects into two groups, one for red and the other for blue.
def separate_objects(objects): red_group = [] blue_group = [] for obj in objects: if obj.color == 'red': red_group.append(obj) else: blue_group.append(obj) return (red_group, blue_group)
null
Write a Python program to generate a random name from a set of given names.
['John', 'Andy', 'Alex', 'Paul', 'Pippa']
import random names = ["John", "Andy", "Alex", "Paul", "Pippa"] def getRandomName(names): randomIndex = random.randint(0, len(names)-1) return names[randomIndex] if __name__ == '__main__': print(getRandomName(names))
[HI Wikipedia] मैंग फून मैंग फून न्यूज़ीलैण्ड के गिस्बॉर्न शहर के निवर्तमान महापौर हैं। यह चीनी मूल के मुट्ठीभर उन व्यक्तियो में से एक हैं जो न्यूज़ीलैण्ड के किसी शहर के महापौर बने हों। यह अंग्रेज़ी, कैण्टोनी तथा माओरी में धाराप्रवाह हैं। जीवित लोग गिस्बॉर्न क्षेत्र के लोग 1960 में जन्मे लोग
null
null
null
null
Create a Python function to generate a matrix with random numbers in it.
import numpy as np def random_matrix(row, col): matrix = np.random.random((row,col)) print(matrix) random_matrix(3,3) #Outputs: [[0.48281427 0.8640267 0.16479638] [0.65602432 0.37230416 0.05444421] [0.78832705 0.19239374 0.03173512]]
null
Generate a code in python using the tkinter library to create a graphical user interface for a program.
# Importing essential libraries from tkinter import * # Create the root window root = Tk() # Defining the title of the window root.title("GUI created using Tkinter") # Defining the size of the window root.geometry("500x500") # Create the widgets label_1 = Label(root, text = "My First Program needs GUI") #...
null
Create a Python program which sorts elements of an array in ascending order.
[5, 2, 1, 3, 6, 4]
def sort_ascending(array): for i in range(len(array)-1): for j in range(i, len(array)): if array[i] > array[j]: array[i], array[j] = array[j], array[i] return array sort_ascending([5, 2, 1, 3, 6, 4]) # Output = [1, 2, 3, 4, 5, 6]
null
Design a software that reverse orders of string words.
Python programming is fun
def reverse_string_words(string): words = string.split(" ") words.reverse() return ' '.join(words) string = "Python programming is fun" print(reverse_string_words(string))
null
Suggest a way to remove duplicate characters from a string in JavaScript.
The Set data structure can be used to remove duplicate characters from a string in JavaScript. For example: [...new Set("string")].join(""); // returns "strng"
null
Find the index of the first occurrence of the substring “sea” in the following string.
String: "These are the seas"
The index of the first occurrence of “sea” is 8.
null
Write code to return a list of prime numbers in the given range.
Start: 10. End: 15
def get_prime_numbers(start, end): prime_numbers = [] for num in range(start, end + 1): if num > 1: for i in range(2, num): if (num % i) == 0: break else: prime_numbers.append(num) return prime_numbers # print list of prime numbers print(get_prime_numbers(10, 15)) # Output: [11, 13, 15]
null
Write CSS code to position a div in the middle and bottom of the page.
div { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); }
null
Construct a Python dictionary to convert Celsius temperature values to their Fahrenheit equivalents
celsius_to_fahrenheit = { 0 : 32, 10 : 50, 20 : 68, 30 : 86, 40 : 104, 50 : 122, 60 : 140, 70 : 158, 80 : 176, 90 : 194, 100 : 212 }
null
Write a machine learning algorithm in Python to classify books into one of 4 categories: fiction, non-fiction, poetry, textbooks.
An example book title: "Pride and Prejudice"
# Import necessary libraries import pandas as pd import numpy as np import matplotlib.pyplot as plt # Load the data data = pd.read_csv("books_data.csv") # Define feature and target variables X = data['title'] y = data['category'] # Transform words into numerical features # Vectorize feature and target data from skle...
[DE Wikipedia] Angerberg Angerberg ist eine Gemeinde mit Einwohnern (Stand ) im Bezirk Kufstein in Österreich. Die Gemeinde liegt im Gerichtsbezirk Rattenberg. Geografie Die Gemeinde Angerberg liegt oberhalb des Verkehrsknotenpunktes Wörgl am 18 km langen „Mittelgebirgsrücken“, der zwischen der Brandenberger Ache und ...
null
null
null
null
Create a binary classification model in Python for a dataset that has two classes
Not applicable
# Import necessary libraries import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns # Read in the dataset df = pd.read_csv('data.csv') # Split the data into training and test sets X = df.drop('target_class', axis=1) y = df.target_class X_train, X_test, y_train, y_test = train_tes...
null
Create a loop that prints all numbers 1 to 100 with the exception of multiples of 5.
for i in range(1,101): if i % 5 != 0: print(i)
null
Rewrite the following piece of code in Python, that calculates the sum of two variables.
int x = 2; int y = 4; int sum = x + y;
x = 2 y = 4 sum = x + y print(sum) # 6
null
Vysvětli rekurzi česky.
Rekurze je technika, kdy funkce volá sama sebe s menším problémem, dokud nedosáhne základní podmínky.
null
How can a programmer optimize a code to improve its performance?
A programmer can optimize a code to improve its performance by using techniques like loop optimization, code refactoring, resource optimization, cache optimization, and parallel computing. Loop optimization involves reducing the number of iterations in loops, using variables instead of literals, removing redundant loop...
null
Create a program in Python to take one input argument, a string, and return a new string with the last character of the string repeating n times, where n is the length of the string.
def repeat_last_character(s): # base case: if string is empty if len(s) == 0: return '' final_char = s[-1] # last character of the string result = final_char * len(s) # repeat the last character n times, where n is the length of the string return result # Example string = 'Hello' print(re...
null
Create a Python program for a text editor that replaces all instances of a specified pattern with a different text string.
string = "Hello world!" pattern = "Hello" replacement = "Goodbye"
# Function to replace a given pattern with a different string def replace_pattern(string, pattern, replacement): # Split string into list of words words = string.split() # Go through each word and replace the pattern for i in range(len(words)): if words[i] == pattern: words[i] = rep...
null
Given an array of numbers, write a prototype JavaScript function to find the average value of all numbers in the array
[6, 5, 8, 10]
function findAverage(numbers) { let sum = 0; for (number of numbers) { sum += number; } return sum / numbers.length; }
null
Create an algorithm in Python to combine two sorted lists into a single sorted list.
list1 = [3, 5, 7] list2 = [1, 2, 4]
def merge_lists(lst1, lst2): sorted_list = [] i=j=0 while (i<len(lst1) and j<len(lst2)): if lst1[i] <= lst2[j]: sorted_list.append(lst1[i]) i+=1 else: sorted_list.append(lst2[j]) j+=1 sorted_list += lst1[i:] sorted_list += lst2[j:] return sorted_list list1 = [3, 5, 7] list2 = [1, 2, 4] print(merge_lists(list1, list2))
[EN Wikipedia] Henry Stanyford Blanckley Henry Stanyford Blanckley (29 September 1752) also known as HSB, was an officer of the 31st Regiment of Foot, captain of the 97th Regiment of Foot (1780), gamekeeper in Little Hallingbury, Essex, and British Consul for Menorca and Algiers. A variety of family stories attribute ...
null
null
null
null
Write a function in Python to extract domain name from given URLs.
"http://www.google.com"
import re def extract_domain_name(url): regex = r"://([^/]+)/?" match = re.search(regex, url) if match: return match.group(1) url = "http://www.google.com" domain_name = extract_domain_name(url) print(domain_name) # Output: # google.com
null
Implement a bubble sort algorithm with a Python function that takes an array as input and returns a sorted array.
[8, 1, 5, 7, 3]
def bubble_sort(arr): n = len(arr) # Traverse through all array elements for i in range(n): # Last i elements are already in place for j in range(0, n-i-1): # traverse the array from 0 to n-i-1 # Swap if the element found is greater # than the next element if arr[j] > arr[j+1] : a...
null
Using SQL, select the names of all employees with the title "Manager".
SELECT name FROM Employees WHERE title = 'Manager';
null
Write an R code to return the first 10 rows of a data frame.
states-data.csv
# Load the data states_data <- read.csv("states-data.csv") # Get the first 10 rows head(states_data, 10)
null
Use Selenium Webdriver to create a Python program that navigates to the Google homepage, searches for "GPT" and prints the h2 element in the result page.
Not applicable
from selenium import webdriver # set chrome driver driver = webdriver.Chrome() # open google driver.get("https://www.google.com/") # find search box and enter "GPT" search = driver.find_element_by_name("q") search.send_keys("GPT") # click search search.submit() # print h2 element h2 = driver.find_element_by_tag_na...
null
Write a python program that takes a dictionary as input and returns a list of its values.
data = { "key1": "value1", "key2": "value2", "key3": "value3" }
def get_values(data): """ Gets the values from a dictionary. Args: data (dict): The dictionary from which to get the values Returns: values (list): A list of the values from the dictionary """ values = [] for value in data.values(): values.append(value) ...
null
Generate a unique key using the following string.
my_str = "Hello World"
import uuid key = uuid.uuid5(uuid.NAMESPACE_DNS, my_str)
[CS Wikipedia] Charles Gustafsson Charles Gustafsson (* 25. prosince 1932) je bývalý švédský fotbalista, který hrával na pozici záložníka. Fotbalová kariéra Celou svou kariéru strávil v klubu Malmö FF. Dvakrát nastoupil za švédskou fotbalovou reprezentaci, branku nevstřelil. Bylo to 25. září 1955 proti Norsku (remíza ...
null
null
null
null
Design a sorting algorithm in Python that uses two lists.
list1 = [3, 2, 5, 4, 1] list2 = [0, 1, 1, 0, 1]
def sort_two_lists(list1, list2): """Function to sort two lists by the order of list2""" zipped_lists = zip(list1, list2) zipped_lists = sorted(zipped_lists, key=lambda x: x[1]) sorted_list1, sorted_list2 = zip(*zipped_lists) return list(sorted_list1), list(sorted_list2)
[HI Wikipedia] इम्फाल इम्फाल (ꯏꯝꯐꯥꯜ) भारत के मणिपुर राज्य की राजधानी है। इस ऐतिहासिक नगर के केन्द्र में भूतपूर्व मणिपुर राज्य की गद्दी, कंगला महल, के खण्डहर उपस्थित हैं। इम्फाल नगर इम्फाल पश्चिम ज़िले और इम्फाल पूर्व ज़िले दोनों में विस्तारित है, और शहर की अधिकांश आबादी इसके पश्चिमी भाग में निवास करती है। इम्फाल भारत ...
null
null
null
[CS Wikipedia] Kostel svatého Karla Boromejského Kostelů zasvěcených Karlu Boromejskému je více: v Praze Kostel svatého Karla Boromejského (Malá Strana) – v areálu Nemocnice Milosrdných sester sv. Karla Boromejského (dříve Pod Petřínem) Kostel svatého Karla Boromejského a Panny Marie – zrušený, součást Vlašského špitá...
null
null
null
null
We have a given string. Replace every occurrence of 'a' with 'A'
string = 'I like apples'
string = 'I like Apples'
[HI Wikipedia] हरियाणा हरियाणा उत्तर भारत का एक राज्य है जिसकी राजधानी चण्डीगढ़ है। इसकी सीमायें उत्तर में पंजाब और हिमाचल प्रदेश, दक्षिण एवं पश्चिम में राजस्थान से जुड़ी हुई हैं। यमुना नदी इसके उत्तर प्रदेश राज्य के साथ पूर्वी सीमा को परिभाषित करती है। राष्ट्रीय राजधानी दिल्ली हरियाणा से तीन ओर से घिरी हुई है और फलस्...
null
null
null
[CS Wikipedia] Bitva u Atuatuka Bitva u Atuatuca byla jednou z bitev galských válek Julia Caesara, která se odehrála v říjnu roku 54 př. n. l. v údolí řeky Le Geer u Atuatuka, pravděpodobně dnešního města Tongeren. Římská legie a pět kohort pod velením římských legátů Tituria Sabina a Lucia Cotty zde byly kmenem Eburo...
null
null
null
null
Print the even numbers in a given array?
array = [2, 3, 4, 5, 6, 7, 8, 9];
let array = [2, 3, 4, 5, 6, 7, 8, 9]; for (let i=0; i<array.length; i++) { if (array[i] % 2 === 0) { console.log(array[i]); } }
null
Write a JavaScript code to print the pyramid pattern for a given number of rows.
7
function pyramid(n) { for (let i = 0; i < n; i++) { let str = ''; for (let j = 0; j < n-i; j++) { str = str + ' '; } for (let k = 0; k <= i; k++ ) { str = str + '* '; } console.log(str); } } pyramid(7);
null
Create a Python code snippet toshuffle a given list of numbers.
[1, 2, 3, 4, 5]
import random def shuffle_list(list_nums): random.shuffle(list_nums) print("Shuffled list :", list_nums) list_nums = [1, 2, 3, 4, 5] shuffle_list(list_nums)
null
Convert the below JSON data into an equivalent XML format.
{ "name": "John", "age": 30, "address": { "street": "1 Main Street", "city": "London", "country": "UK" } }
<?xml version="1.0"?> <data> <name>John</name> <age>30</age> <address> <street>1 Main Street</street> <city>London</city> <country>UK</country> </address> </data>
null
Produce a Python program to compute the Fibonacci number for a given integer.
8
def getFibonacci(n): if n<0: print("Incorrect input") elif n==1: return 0 elif n==2: return 1 else: return getFibonacci(n-1)+getFibonacci(n-2) number = 8 fibonacci_number = getFibonacci(number) print(fibonacci_number)
[DE Wikipedia] Simon the Sorcerer: Wer will schon Kontakt? Simon the Sorcerer: Wer will schon Kontakt? ist ein Computerspiel des deutschen Spieleentwicklers Silver Style Entertainment aus dem Jahr 2009. Das Adventure ist der fünfte Teil der Spieleserie Simon the Sorcerer und der zweite Teil nach Simon the Sorcerer: Ch...
null
null
null
null
Why should you use functions in programming?
Using functions in programming helps to break down complex tasks into more manageable pieces, which makes code easier to read and maintain. Functions also allow for the reuse of code, which can help to reduce overall development time and resources. Additionally, functions improve code organization and enable functions ...
null
How can you sort a list of dictionaries by values of the dictionary in Python?
def sort_dict_by_values(dict_list): return sorted(dict_list, key=lambda k: k['value'])
null
Write some code in JavaScript to generate an array with 3 positive random integers.
function getRandomIntegers(size) { return [...Array(size)].map( () => Math.floor(Math.random() * Math.floor(20)) ).filter(randomNumber => randomNumber > 0); } getRandomIntegers(3); //Returns an array with 3 random positive integers
[CS Wikipedia] Dráha Dráha je slovo slovanského původu, označující původně (v podobě „dorga“, česky draha) cestu mezi poli, kterou se vyháněl dobytek, tj. průhon. Podle jiného zdroje slovo „draha“ pro označení cest nižší kvality je odvozeno od slovesa „dražání“, které znamenalo mýcení a klučení dřevin. V dnešní době m...
null
null
null
null
Create a Python class called Rectangle to represent a two-dimensional rectangle with a length and width.
class Rectangle: def __init__(self, length, width): self.length = length self.width = width def area(self): return self.length * self.width
null
Write a Python program to create a line chart displaying numbers from 1 to 15.
import matplotlib.pyplot as plt data = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] # making the line plot plt.plot(data, '-o') # '-o' is used to connected the dots # naming the x axis plt.xlabel('x - axis') # naming the y axis plt.ylabel('y - axis') # giving a title to my graph plt.title('Line chart of numbers from 1 to ...
null
Construct an HTML table with two columns and 4 rows.
<table> <tr> <th>First Column</th> <th>Second Column</th> </tr> <tr> <td>Row 1</td> <td>Row 1</td> </tr> <tr> <td>Row 2</td> <td>Row 2</td> </tr> <tr> <td>Row 3</td> <td>Row 3</td> </tr> <tr> <td>Row 4</td> <td>Row 4</td> </tr> </table>
null
What is the time complexity of the most_common() function?
The time complexity of the most_common() function is O(n).
null
Create a basic implementation of a linked list using Python.
class Node: def __init__(self, data): self.data = data self.next = None class LinkedList: def __init__(self): self.head = None def push(self, new_data): new_node = Node(new_data) new_node.next = self.head self.head = new_node def pri...
null
What is the difference between shallow copying and deep copying?
Shallow copying is the process of creating a copy of the original object which only contains references to the values contained in the original instance. This means that any shallow copy only contains references to the same objects as the original instance, while any changes made to the copy will be reflected in the or...
null
Generate a Python class that takes a single number as an argument, which indicates an array size, and calculate the median value of the array
arr_size = 10
class MedianCalculator: def __init__(self, arr_size): self.arr_size = arr_size self.arr = [] def calculate_median(self): if self.arr_size == 0: return 0 elif self.arr_size == 1: return self.arr[0] else: self.arr.sort() ...
null
What is the correct way to find the length of an array in Java?
The correct way to find the length of an array in Java is to use the length field of the array. For example: int[] arr = new int[10]; int len = arr.length; // len is now 10
[HI Wikipedia] येम्तलान्द लैन येम्तलान्द लैन (स्वीडी: Jämtlands län, अंग्रेज़ी: Jämtland) स्वीडन का एक लैन है। 'लैन' स्वीडन का उच्च-स्तरीय प्रशासनिक विभाग होता है, जिसे कभी-कभी 'काउंटी' भी कहते हैं। इन्हें भी देखें स्वीडन की काउंटियाँ सन्दर्भ येम्तलान्द लैन स्वीडन की काउंटियाँ स्वीडन
null
null
null
[DE Wikipedia] Ministerium für Arbeit und sozialen Schutz der Russischen Föderation Das Ministerium für Arbeit und soziale Sicherheit der Russischen Föderation ist das Sozialministerium Russlands und eines der 16 Ministerien der Russischen Regierung. Aufgaben und Organisation Das Ministerium beschäftigt sich mit Arbei...
null
null
null
null
Use object-oriented programming principles in Python to create a class to represent a User profile.
class UserProfile(): def __init__(self, name, email, address, phone_number): self.name = name self.email = email self.address = address self.phone_number = phone_number def get_name(self): return self.name def get_email(self): return self.email def get_...
null
Create a random matrix using NumPy where the elements have 2 decimal places.
import numpy as np # Create a 2×2 matrix random_matrix = np.random.rand(2,2) # Round to two decimal places np.around(random_matrix, decimals=2)
[DE Wikipedia] Lithocarpus edulis Lithocarpus edulis ist eine Pflanzenart aus der artenreichen Gattung Lithocarpus in der Unterfamilie Quercoideae innerhalb der Familie der Buchengewächse (Fagaceae). Sie ist in Japan heimisch und wird in warm-gemäßigten, frostfreien Gebieten als Zierpflanze verwendet. Beschreibung Lit...
null
null
null
[DE Wikipedia] Willibald Franz Kammel Willibald Franz Kammel (* 27. Mai 1879 in Steinschönau, Bezirk Tetschen, Böhmen; † 16. April 1953 in Wien) war ein österreichischer Pädagoge und Psychologe. Leben Kammel war ein älterer Bruder von Architekt Leo Kammel. Er Studierte an den Universitäten Wien, Grenoble, Salzburg, Ha...
null
null
null
null
Create a Python program to reverse a string in place.
"Hello World!"
def reverse_string_in_space(s): temp_list = list(s) start = 0 end = len(temp_list) - 1 while start < end: temp_list[start], temp_list[end] = temp_list[end], temp_list[start] start += 1 end -= 1 s = "".join(temp_list) return s s = "Hello World!" print(...
[EN Wikipedia] Emeritus Senior Living Emeritus Corporation doing business as Emeritus Senior Living was a provider of independent living, assisted living, Alzheimer's care, and skilled nursing for seniors living in Emeritus communities throughout the United States. The company was founded in 1993, and was acquired by ...
null
null
null
[EN Wikipedia] 1967–68 Norwegian 1. Divisjon season The 1967–68 Norwegian 1. Divisjon season was the 29th season of ice hockey in Norway. Eight teams participated in the league, and Valerenga Ishockey won the championship. First round Final round External links Norwegian Ice Hockey Federation Nor Eliteserien (ice hock...
null
null
null
null
Design an algorithm in Python to find the second smallest number in an array.
[45, 25, 12, 34, 36]
def second_smallest_num(arr): min1 = min(arr) arr.remove(min1) min2 = min(arr) return min2 arr = [45, 25, 12, 34, 36] res = second_smallest_num(arr) print(res)
[DE Wikipedia] Legendre (Mondkrater) Legendre ist ein Einschlagkrater im Osten der Mondvorderseite, südöstlich des Mare Fecunditatis, westlich des Kraters Humboldt und südöstlich von Petavius. Der etwa oval geformte Krater ist stark erodiert, das Innere weitgehend eben. Der Krater wurde 1935 von der IAU nach dem franz...
null
null
null
null
Modify the code below to make it a one-liner
# Initialize a variable sum = 0 # Iterate over numbers from 1 to 10 for i in range(1, 11): # Add number to sum sum = sum + i # Print sum print(sum)
print(sum([i for i in range(1, 11)]))
[CS Wikipedia] Švýcarská hokejbalová reprezentace Švýcarská hokejbalová reprezentace je výběrem nejlepších švýcarských hráčů v hokejbale. Od roku 1996 se účastní mistrovství světa a do roku 2000 mistrovství Evropy. Tým je řízen Švýcarskou hokejbalovou asociací, která je členem ISBHF. Největším úspěchem švýcarského tým...
null
null
null
null
Create a JSON object with the following data: three fruits of each color {red: [apple, watermelon, strawberry], green apple, kiwi, honeydew], yellow: [banana, lemon, mango]}
{ "red": ["apple", "watermelon", "strawberry"], "green": ["apple", "kiwi", "honeydew"], "yellow": ["banana", "lemon", "mango"] }
[DE Wikipedia] Liste der Wappen im Kreis Pinneberg Diese Liste zeigt die Wappen des Kreises Pinneberg (Schleswig-Holstein) mit seinen Städten, Gemeinden und Ämtern. Kreiswappen Amtsfreie Städte und Gemeinden Ämter Amt Elmshorn-Land Amt Geest und Marsch Südholstein Amt Hörnerkirchen Amt Pinnau Amt Rantzau Ehemalige Ämt...
null
null
null
[EN Wikipedia] 1892 Michigan gubernatorial election The 1892 Michigan gubernatorial election was held on November 1, 1892. Republican nominee John T. Rich defeated Democratic candidate Allen B. Morse with 47.21% of the vote. General election Candidates Major party candidates John T. Rich, Republican Allen B. Morse, De...
null
null
null
null
Insert 'value' into the dictionary 'dic' at the key 'key'.
dic = {'a':1, 'b':2} key = 'c' value = 3
dic[key] = value
null
Write a code in Python to print all numbers between 2000 and 3200, which are divisible by 7 and multiple of 5.
def divisible_numbers(): for num in range(2000, 3201): if (num % 7 == 0) and (num % 5 == 0): print(num, end=", ") if __name__ == '__main__': divisible_numbers()
null
Write a SQL statement that joins three tables and returns the fields of interest.
Table 1 (tbl_person): person_name, person_id Table 2 (tbl_course): course_id, course_name Table 3 (tbl_enroll): person_id, course_id Fields of Interest: person_name, course_name
SELECT tbl_person.person_name, tbl_course.course_name FROM tbl_person INNER JOIN tbl_enroll on tbl_person.person_id = tbl_enroll.person_id INNER JOIN tbl_course on tbl_enroll.course_id = tbl_course.course_id;
null
Generate pseudo-random numbers in Python.
# Generate pseudo-random numbers in Python import random # Generate a pseudo-random number between 0 and 1 num = random.random() print("Pseudo-random number between 0 and 1: ", num) # Generate pseudo-random numbers from a discrete set num = random.choice([1, 2, 3, 4, 5]) print("Pseudo-random number from a discrete s...
null
Write a Python program to round a number to a given number of decimal places.
number = 2.68 round_places = 2
number_rounded = round(number, round_places) print(number_rounded) # Output: 2.68
null
Write a Python program to replace all the vowels in the given string with '_'.
String: Python is a very interesting language
def replace_vowels(string): vowels = ["a", "e", "i", "o", "u"] res = [] for letter in string.lower(): if letter in vowels: res.append('_') else: res.append(letter) return ''.join(res)
null
Can you provide a Python program that prints the largest element in the given list?
[1, 3, 4, 5, 19, 13, 7]
def get_largest(nums): max_num = nums[0] for num in nums: if num > max_num: max_num = num return max_num print(get_largest([1, 3, 4, 5, 19, 13, 7]))
null
Compose a function to generate a palette of random colors.
import random def generate_palette(n): palette = [] for i in range(n): rgb = [] for j in range(3): rgb.append(random.randint(1, 255)) palette.append(rgb) return palette if __name__ == "__main__": n = 10 palette = generate_palette(n) print(palette)
[DE Wikipedia] Schloss Hausen (Neu-Ulm) Das Schloss Hausen steht in Hausen in Neu-Ulm im bayerischen Regierungsbezirk Schwaben. Baugeschichte Das Schloss ist ein ehemaliger Ulmer Patriziersitz, ein zweigeschossiges Schloss mit Mansarddach. Das ursprüngliche von dem Ulmer Patrizier Roth um 1573 erbaute Schloss Hausen w...
null
null
null
null
Generate a random alphanumeric string in Python of length 10.
Not applicable
import random alphanumeric_string = ''.join(random.choices(string.ascii_letters + string.digits, k=10)) print(alphanumeric_string)
null
Write a SQL query to retrieve players with a score equal to or greater than 80.
CREATE TABLE `players` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(30) NOT NULL, `score` int(11) NOT NULL, PRIMARY KEY(`id`) );
SELECT * FROM `players` WHERE `score` >= 80;
[CS Wikipedia] Lokomotiva S 699.1 Lokomotiva řady S 699.1 (od 1988 řada 260) byla elektrická lokomotiva vyrobená Škodou Plzeň. Jediný kus této řady, S 699.1001, vznikl v roce 1968 modernizací (tovární typ 52Em) prototypové lokomotivy ČS4-001 (z roku 1963, tovární typ 52E) pro použití na Železničním zkušebním okruhu Ce...
null
null
null
null
Create a function that takes an array and returns true if it contains all the elements in an another array.
array1 = [1, 2, 3, 4] array2 = [1, 2, 3]
def checkArray(array1, array2): for element in array2: if element not in array1: return False return True array1 = [1, 2, 3, 4] array2 = [1, 2, 3] print(checkArray(array1, array2)) # Output # True
null
Write a code to identify the longest palindrome in a given string
String: kayakracecar
def get_longest_palindrome(s): longest_palindrome = '' s_length = len(s) for i in range(s_length): for j in range(i, s_length): substring = s[i:j + 1] if len(substring) > len(longest_palindrome) and substring == substring[::-1]: longest_palindrome = substring return longest_palindrome # Verify it works print(get_longes...
null
Create a regex expression that captures a valid URL.
^(https?:\/\/)([\da-zA-Z\.-]+)\.([a-zA-Z\.]{2,6})([\/\w \.-]*)*\/?$
[CS Wikipedia] Taťána Polnovová Taťána Polnovová (), rozená Zajkovová (), (* 20. dubna 1979, Krasnodar) je ruská atletka, která získala bronzovou medaili na mistrovství Evropy 2006 v Göteborgu ve skoku o tyči. V roce 2003 vybojovala na světové letní univerziádě v jihokorejském Tegu zlatou medaili. V letech 1998–2002 r...
null
null
null
null
Reverse an input string.
def reverse_string(s): return s[::-1]
null
Add a comment to explain the purpose of the following code.
for i in range(100): print(i)
# Prints all numbers from 0 to 99 for i in range(100): print(i)
[EN Wikipedia] LANSA (Colombia) Lansa (acronym for Limitada Nacional de Servicio Aéreo y luego de Líneas Aéreas Nacionales) was an airline company based in Barranquilla , Colombia. History The Beginning After 1945 the company, Avianca had a complete monopoly over the airline industry. A couple of mechanics and pilots ...
null
null
null
null
Write a Python program to flatten a list of lists into a single list.
List of lists: [[1,2], [3], [4,5,6]]
import itertools # flatten a list of lists list_of_lists = [[1,2], [3], [4,5,6]] flattened_list = list(itertools.chain.from_iterable(list_of_lists)) # print the flattened list print(flattened_list) # Output: [1, 2, 3, 4, 5, 6]
null
Write a Java program to print out a triangle of stars.
3
* ** ***
null
Write a function that checks if a give number is even or odd.
def is_even(n): if n%2 == 0: return True else: return False
[HI Wikipedia] पोप पादरी वर्ग को पोप कहा जाता है रोमन कैथोलिक चर्च के सर्वोच्च धर्म गुरु, रोम के बिशप एवं वैटिकन के राज्याध्यक्ष को पोप कहते हैं। 'पोप' का शाब्दिक अर्थ 'पिता' होता है। यह लैटिन के "पापा" (papa) से व्युत्पन्न हा है जो स्वयं ग्रीक के पापास् (πάπας, pápas) से व्युत्पन्न है। इस समय pope frncis naye इस पद प...
null
null
null