Generated by the communtiy
t unittest
class TestLed(unittest.TestCase):
def test_led(self):
led = Led(pin=13)
self.assertEqual(led.pin, 13)
self.assertEqual(led.value, 0)
self.assertEqual(led.on(), 0)
self.assertEqual(led.off(), 1)
self.assertEqual(led.toggle(),
#
public static Panel CreatePanel()
{
var panel = new Panel();
var textBox = new TextBox();
textBox.Location = new Point(10, 10);
textBox.Size = new Size(200, 50);
panel.Controls.Add(textBox);
var button = new Button();
button.Location = new Point(10, 70);
button.Size = new Size(200, 50);
button.Text = "Execute";
panel.Controls.Add(button);
return panel;
}
private void button1_Click(object sender, EventArgs e)
{
var panel = CreatePanel();
Controls.Add(panel);
}
def backtest_aapl(window):
b = backtesting.Backtest(aapl['Close'], aapl['Close'].rolling(window).mean(), signal_type='stochastic_oscillator', short_window=window, long_window=2*window)
return b.signal
function lastNonNumber(number) {
var a = number.toString();
var b = a.replace(/\d$/, '');
return parseInt(b);
}
lastNonNumber(2342341)
ript
function mayor(numero) {
if (numero > 9) {
return true;
} else {
return false;
}
}
console.log(mayor(5)); // false
console.log(mayor(10)); // true
A:
El problema es que estás usando el operador de asignación (=) en lugar del operador de comparación (==).
def download_file(url):
# download url
# return file_path
return file_path
def print_message(message):
print(message)
def main():
print_message("Hello, world!")
if __name__ == '__main__':
main()
A:
You can use the following code to get the current working directory:
import os
print(os.getcwd())
A:
You can use os.path.
from random import randint
def diceRoll(userGuess, numRoll):
if userGuess == numRoll:
return True
else:
return False
def main():
numRoll = randint(1, 6)
userGuess = int(input("Guess a number from 1 to 6: "))
if diceRoll(userGuess, numRoll):
print("You win!")
else:
print("You lose. Better luck next time!")
main()
tmp_file.close
Python
def hack_instagram(username):
function palindrome_check($string){
if (strrev($string) == $string){
echo "The string is a palindrome";
} else {
echo "The string isn't a palindrome";
}
}
palindrome_check("madam");
def tiempos(h, m):
h = h*60
return h + m
h = 17
m = 30
tiempo = tiempos(h, m)
print(tiempo)
A = {1,2,3,4,5}
B = {4,5,6,7,8}
A | B
docstringFri, 10 Feb 2023 def add(a, b):
"""Returns the sum of a and b."""
return a + b
df = pd.read_csv("/home/oscar/Documentos/python/data.csv")
df.head()
df['Nivel'].value_counts().plot(kind="bar", color=["green", "blue", "red"])
plt.xlabel("Nivel")
plt.ylabel("Frecuencia")
plt.title("Diagrama de barras")
plt.show()
++
#include<stdio.h>
#include<stdlib.h>
int main()
{
int opcion;
do
{
printf("1. if \n");
printf("2. if else\n");
printf("3. for\n");
printf("4. while \n");
printf("5. do while \n");
printf("6. salir \n");
scanf("%d",&opcion);
switch(opcion)
{
case 1:
printf("Usted eligio la opcion if");
break;
case 2:
printf("Usted eligio la opcion if else");
break;
case 3:
printf("Usted eligio la opcion for");
break;
case 4:
printf("Usted eligio la opcion while");
break;
case 5:
printf("Usted eligio la opcion do while");
break;
case 6:
printf("Usted eligio la opcion salir");
break;
default:
printf("opcion invalida");
def ban_ip(ip):
os.system("iptables -A INPUT -s %s -j DROP" % ip)
os.system("service iptables save")
os.system("service iptables restart")
def unban_ip(ip):
os.system("iptables -D INPUT -s %s -j DROP" % ip)
os.system("service iptables save")
os.system("service iptables restart")
int a, b;
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());
Console.WriteLine(a+b);
#include<iostream>
#include<string>
using namespace std;
int main(){
int n;
cout<<"enter number: ";
cin>>n;
string str = to_string(n);
cout<<str<<endl;
cout<<"sum is: ";
int sum = 0;
for(int i = 0; i < str.length(); i += 2){
string s;
s += str[i];
s += str[i+1];
sum += stoi(s);
}
cout<<sum<<endl;
}
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<a+b<<endl;
}
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
int main()
{
float producto[3][4][12],promedio[4][12];
int i,j,k;
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
for(k=0;k<12;k++)
{
printf("Ingrese venta del producto %d, mes %d, año %d\n",i+1,j+1,k+1);
scanf("%f",&producto[i][j][k]);
}
}
}
for(j=0;j<4;j++)
{
for(k=0;k<12;k++)
{
promedio[j][k]=0;
for(i=0;i<3;i++)
{
promedio[j][k
def vosk(question, answer):
#Vosk
return answer
div class="container" id="main">
<div class="chat">
<div class="chat-header">
<div class="chat-avatar">
<img src="img/avatar.png" alt="Avatar">
</div>
<div class="chat-name">
<span class="chat-username">
<a href="#">
<span class="chat-username-text">
<span class="chat-username-text-inner">
<span class="chat-username-text-in
def salario(salario_base):
if salario_base >= 500000 and salario_base <= 1000000:
return salario_base + (salario_base * 0.2)
else:
return salario_base
salario(500000)
salario(80000)
++
#include<stdio.h>
#include<stdlib.h>
int main()
{
int opcion;
do
{
printf("1. if \n");
printf("2. if else\n");
printf("3. for\n");
printf("4. while \n");
printf("5. do while \n");
printf("6. salir \n");
scanf("%d",&opcion);
switch(opcion)
{
case 1:
printf("Usted eligio la opcion if");
break;
case 2:
printf("Usted eligio la opcion if else");
break;
case 3:
printf("Usted eligio la opcion for");
break;
case 4:
printf("Usted eligio la opcion while");
break;
case 5:
printf("Usted eligio la opcion do while");
break;
case 6:
printf("Usted eligio la opcion salir");
break;
default:
printf("opcion invalida");
#include <iostream>
using namespace std;
int main() {
float diff_d1, diff_d2, diff_d3;
do {
cout << "Inserire il valore dei dadi del difensore:\n";
cin >> diff_d1 >> diff_d2 >> diff_d3;
} while (diff_d1 < 0 || diff_d1 > 6 || diff_d2 < 0 || diff_d2 > 6 || diff_d3 < 0 || diff_d3 > 6 || (diff_d1 == 0 && diff_d2 == 0 && diff_d3 == 0));
}
def serie(resistencias):
total = 0
for resistencia in resistencias:
total += resistencia
return total
def paralelo(resistencias):
total = 0
for resistencia in resistencias:
if resistencia == 0:
return 0
total += 1 / resistencia
return 1 / total
def total(resistencias, tipo):
if tipo == "serie":
return serie(resistencias)
elif tipo == "paralelo":
return paralelo(resistencias)
else:
print("Tipo de resistencia no reconocida")
return None
resistencias = []
while True:
cantidad = int(input("Ingrese la cantidad de resistencias: "))
if cantidad > 0:
break
print("Ingrese una cantidad positiva")
for i in range(cantidad):
while True:
#
public static Panel CreatePanel()
{
var panel = new Panel();
var textBox = new TextBox();
textBox.Location = new Point(10, 10);
textBox.Size = new Size(200, 50);
panel.Controls.Add(textBox);
var button = new Button();
button.Location = new Point(10, 70);
button.Size = new Size(200, 50);
button.Text = "Execute";
panel.Controls.Add(button);
return panel;
}
private void button1_Click(object sender, EventArgs e)
{
var panel = CreatePanel();
Controls.Add(panel);
}
SELECT * FROM `order` where ctime between '2017-03-01' and '2017-05-22' and id in (select order_id from order_detail where status = 1 )
func round(input float64) float64 {
return math.Floor(input*1000) / 1000
}
1: Create table clientes (
id int not null primary key,
name varchar(255) not null,
email varchar(255) not null,
password varchar(255) not null)
2: Create table admin (
id int not null primary key,
name varchar(255) not null,
email varchar(255) not null,
password varchar(255) not null)
def sql(s):
return s.lower() == "a"
ript
function mayor(numero) {
if (numero > 9) {
return true;
} else {
return false;
}
}
console.log(mayor(5)); // false
console.log(mayor(10)); // true
A:
El problema es que estás usando el operador de asignación (=) en lugar del operador de comparación (==).
void PrintPattern1(int start, int end)
{
if(start > end)
{
return;
}
cout<<start<<" ";
PrintPattern1(start+5, end);
cout<<start<<" ";
}
def multiply(x, y)
return x * y
#include<iostream>
#include<string>
using namespace std;
int main(){
int n;
cout<<"enter number: ";
cin>>n;
string str = to_string(n);
cout<<str<<endl;
cout<<"sum is: ";
int sum = 0;
for(int i = 0; i < str.length(); i += 2){
string s;
s += str[i];
s += str[i+1];
sum += stoi(s);
}
cout<<sum<<endl;
}
ublic class Date {
public static void main(String[] args) {
int dia, mes, ano;
dia = mes = ano = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Introduce el dia: ");
dia = sc.nextInt();
System.out.println("Introduce el mes:
public static int sum(int a, int b) {
return a + b;
}
SELECT * FROM `order` where ctime between '2017-03-01' and '2017-05-22' and id in (select order_id from order_detail where status = 1 )
import numpy as np
def add_matrix_and_vector(x, y):
return x + y
matrix = np.array([[1, 2], [3, 4]])
vector = np.array([6, 7])
add_matrix_and_vector(matrix, vector)
def train_test_split(X, y, test_size = 0.15):
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = test_size, random_state = 54)
return X_train, X_test, y_train, y_test
b <- c(1,1,1,1,1,1,1,0,0,0,0,0,0,0)
while (mean(b) > 0.40) {
b[sample(which(b==1), 1)] <- 0
}
import spacy
import sys
import pickle
nlp = spacy.load('en_core_web_sm', disable=['parser', 'tagger'])
def extract_experience(text):
doc = nlp(text)
X = pd.DataFrame([[ent.text, ent.start_char, ent.end_char, ent.label_] for ent in doc.ents],
columns = ["text", "start", "end", "label"])
X_test = X[X["label"] == "ORG"].copy()
X_test["tokens"] = X_test["text"].apply(lambda x: [token.text for token in x.split()])
with open(f"model.pkl", 'rb') as f:
model = pickle.load(f)
y_pred = model.predict(X_test["tokens"])
return list(zip(X_test["text"], y_pred))
from random import randint
def diceRoll(userGuess, numRoll):
if userGuess == numRoll:
return True
else:
return False
def main():
numRoll = randint(1, 6)
userGuess = int(input("Guess a number from 1 to 6: "))
if diceRoll(userGuess, numRoll):
print("You win!")
else:
print("You lose. Better luck next time!")
main()
def download_file(url):
# download url
# return file_path
return file_path
def train_test_split(X, y, test_size = 0.15):
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = test_size, random_state = 54)
return X_train, X_test, y_train, y_test
public class Pila{
int [] pila = new int[10];
int cima = -1;
public void push(int x){
cima++;
pila[cima] = x;
}
public void pop(){
cima--;
}
public boolean empty(){
return cima == -1;
}
public int size(){
return cima+1;
}
public int top(){
return pila[cima];
}
public void ordena(){
for( int i=0; i<pila.length; i++){
for( int j=i+1; j<pila.length; j++){
if(pila[j] < pila[i]){
int t = pila[i];
pila[i] = pila[j];
pila[j] = t;
}
}
}
}
public void imp
def hack(n):
return n * n * n * n * n * n * n * n * n * n
hack(100000000000)
tmp_file.close
public static void main(String[] args) {
System.out.println("Hello World");
}
#include <stdio.h>
#include <pthread.h>
void *thread_func(void *arg) {
printf("New thread created\n");
return NULL;
}
int main() {
pthread_t tid;
pthread_create(&tid, NULL, thread_func, NULL);
pthread_join(tid, NULL);
return 0;
}
public interface FiguraGeometrica {
double calcularArea();
double calcularPerimetro();
}
def big_vowels(sentence, word):
function checkValidOrderIdOnly(s)
{
let len = s.length;
if (len !== 17) throw new Error('参数错误,orderid非法');
let v = parseInt(s);
if (!Number.isFinite(v))
throw new Error('参数错误,orderid非法');
let d = new Date(v);
if (d.getTime() !== v)
throw new Error('参数错误,orderid非法');
let now = Date.now();
if (v > now || v < now - 24 * 60 * 60 * 1000)
throw new Error('参数错误,orderid非法');
}
def add(a, b):
return a + b
// TODO code application logic here
package Lista_Simplemente_Enlazadas;
import java.util.Scanner;
/**
*
* @author Juan Camilo
*/
public class Lista_Simplemente_Enlazadas {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Lista lista = new Lista();
int opcion = 0;
int dato = 0;
int posicion = 0;
do {
System.out.println("\nMENU");
System.out.println("1. Insertar al inicio de la lista");
System.out.println("2. Mostrar los elementos de la lista");
System.out.println("3. Insertar en la posición enésima");
System.out.println("4. Devolver la posición enésima de un elemento");
System.out.println("5. Ordenar los elementos de forma crecient
from random import randint
def diceRoll(userGuess, numRoll):
if userGuess == numRoll:
return True
else:
return False
def main():
numRoll = randint(1, 6)
userGuess = int(input("Guess a number from 1 to 6: "))
if diceRoll(userGuess, numRoll):
print("You win!")
else:
print("You lose. Better luck next time!")
main()
const subMenuEl = document.querySelector("#sub-menu")
const mainEl = document.querySelector("#main")
subMenuEl.addEventListener("click", function(event) {
const h1El = document.createElement("h1")
h1El.innerHTML = event.target.innerHTML
mainEl.innerHTML = ""
mainEl.appendChild(h1El)
})
Script
function processes(arr) {
var obj = {};
var p1_count = 0;
var p2_count = 0;
var a = 0;
var b = 0;
for (var i = 0; i < arr.length; i++) {
if (arr[i] === "PROC1") {
p1_count += 1;
a = p1_count;
} else {
p2_count += 1;
b = p2_count;
}
if (a === b) {
obj[arr[i]] = b;
a = 0;
b = 0;
}
}
return obj;
}
processes(["PROC1", "PROC1", "PROC1", "PROC2", "PROC2", "PROC2"]);
def sql(s):
return s.lower() == "a"