def add(a, b):
return a + b
def subtraction(a, b):
return a - b
def multiplication(a, b):
return a * b
def division(a, b):
return a / b
def square(a, b):
return a ** b
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
return a / b
def modulo(a, b):
return a % b
def power(a, b):
return a ** b
import json
import requests
import time
from datetime import datetime
import random
from pytz import timezone
import pytz
# Token del Bot
TOKEN = "---"
URL = "https://api.telegram.org/bot{}/".format(TOKEN)
# Funcion para obtener el resultado de la ultima actualizacion
def get_url(url):
response = requests.get(url)
content = response.content.decode("utf8")
return content
# Funcion para obtener el JSON de la ultima actualizacion
def get_json_from_url(url):
content = get_url(url)
js = json.loads(content)
return js
# Funcion para obtener las actualizaciones
def get_updates(offset=None):
url = URL + "getUpdates?timeout=100"
if offset:
url += "&offset={}".format(offset)
js = get_json_from_url(url
def math(a, b):
return a + b
math(1, 2)
def add(a, b):
return a + b
def substract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
return a / b
import telebot
token = "token"
tb = telebot.TeleBot(token)
@tb.message_handler(commands=['start', 'help'])
def send_welcome(message):
tb.reply_to(message, "Howdy, how are you doing?")
@tb.message_handler(func=lambda message: True)
def echo_all(message):
tb.reply_to(message, message.text)
tb.polling()
def calculator(a, b):
print(a+b)
print(a-b)
print(a*b)
print(a/b)
calculator(10, 2)
from telegram.ext import Updater, CommandHandler
def welcome(bot, update):
bot.send_message(chat_id=update.message.chat_id, text="Welcome to the PythonMathBot")
def cuadrado(bot, update, args):
try:
value = float(args[0])
bot.send_message(chat_id=update.message.chat_id, text=value**2)
except (ValueError, IndexError):
bot.send_message(chat_id=update.message.chat_id, text="Uso: /cuadrado <numero>")
def raiz(bot, update, args):
try:
value = float(args[0])
bot.send_message(chat_id=update.message.chat_id, text=value**0.5)
except (ValueError, IndexError):
bot.send_message(chat_id=update.message.chat_id, text="Uso: /raiz <numero>")
def resta(bot
#Telegram Bot Integration
import telebot
from telebot import types
bot = telebot.TeleBot("TOKEN")
#Claves
keyboard1 = telebot.types.ReplyKeyboardMarkup(True, True)
keyboard1.row('/start')
keyboard1.row('Suma', 'Resta')
keyboard1.row('Multiplicacion', 'Division')
#Funciones
@bot.message_handler(commands=['start'])
def send_welcome(message):
bot.reply_to(message, "¿Qué desea hacer?", reply_markup=keyboard1)
#Suma
@bot.message_handler(commands=['Suma'])
def send_welcome(message):
bot.reply_to(message, "Dijite dos numeros", reply_markup=keyboard1)
@bot.message_handler(func=lambda message: True)
def echo_all(message):
try:
a = int(message.text)
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
return a / b
def calc(a, b, operator):
if operator == '+':
return a + b
elif operator == '-':
return a - b
elif operator == '*':
return a * b
elif operator == '/':
return a / b
print(calc(2, 3, '+'))
print(calc(2, 3, '-'))
print(calc(2, 3, '*'))
print(calc(6, 3, '/'))
import time
import telepot
from telepot.loop import MessageLoop
def handle(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
print(content_type, chat_type, chat_id)
if content_type == 'text':
bot.sendMessage(chat_id, "You said '{}'".format(msg["text"]))
bot = telepot.Bot('1038853634:AAH56qjKNYjb2lRwR9kTcR7B3v2iNnAZWvQ')
MessageLoop(bot, handle).run_as_thread()
print ('Listening ...')
# Keep the program running.
while 1:
time.sleep(10)
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
return a / b
print("Selecciona una operación.")
print("1.Sumar")
print("2.Restar")
print("3.Multiplicar")
print("4.Dividir")
while True:
# Toma el input del usuario
choice = input("Ingrese una opcion (1/2/3/4): ")
# Si el usuario ingresa 1, entonces se realiza una suma
if choice in ('1', '2', '3', '4'):
num1 = float(input("Ingresa el primer numero: "))
num2 = float(input("Ingresa el segundo numero: "))
if choice == '1':
print(num1, "+", num2, "
import telebot
from telebot import types
TOKEN = '958169566:AAGb_8TKQ_aG6A7w-YWmj2P9p2Zgjdv9YIo'
bot = telebot.TeleBot(TOKEN)
def add(a, b):
return a + b
def subt(a, b):
return a - b
def mult(a, b):
return a * b
def div(a, b):
return a / b
@bot.inline_handler(lambda query: len(query.query) > 0)
def query_text(query):
try:
if query.query == "/help":
bot.send_message(query.from_user.id, "Usa los siguientes comandos: \n- /add \n- /subt \n- /mult \n- /div")
return
if query.query == "/add":
markup = types.InlineKeyboardMarkup()
b
import telepot
bot = telepot.Bot("<token>")
print(bot.getMe())
def suma(a, b):
return a + b
suma(1, 2)
from telegram.ext import CommandHandler
def start(bot, update):
update.message.reply_text('Hello World!')
start_handler = CommandHandler('start', start)
dispatcher.add_handler(start_handler)
updater.start_polling()
function add(a, b) {
return a + b
}
function substract(a, b) {
return a - b
}
function multiply(a, b) {
return a * b
}
function divide(a, b) {
return a / b
}
function add(a, b) {
return a + b;
}
function subtract(a, b) {
return a - b;
}
function multiply(a, b) {
return a * b;
}
function divide(a, b) {
return a / b;
}
var calculate = function(num1, operator, num2) {
if (operator === '+') {
return add(num1, num2);
} else if (operator === '-') {
return subtract(num1, num2);
} else if (operator === '*') {
return multiply(num1, num2);
} else if (operator === '/') {
return divide(num1, num2);
}
};
calculate(1, '+', 2);
calculate(4, '-', 2);
calculate(2, '*', 0);
calculate(12, '/', 0);
num_1 = input("Enter a number: ")
num_2 = input("Enter another number: ")
result = float(num_1) + float(num_2)
print(result)
def operacion(bot, update):
chat_id = update.message.chat_id
ops = update.message.text.split()[1:]
if ops[0] == '+':
result = int(ops[1]) + int(ops[2])
elif ops[0] == '-':
result = int(ops[1]) - int(ops[2])
elif ops[0] == '*':
result = int(ops[1]) * int(ops[2])
elif ops[0] == '/':
result = int(ops[1]) / int(ops[2])
else:
result = 'Syntax error'
bot.send_message(
chat_id=chat_id,
text=result)
updater.dispatcher.add_handler(CommandHandler('operacion', operacion))
function add(a, b){
return a + b
}
function subtract(a, b){
return a - b
}
function multiply(a, b){
return a * b
}
function divide(a, b){
return a / b
}
def calcular(a, b, opcion):
if opcion == 1:
return a + b
elif opcion == 2:
return a - b
elif opcion == 3:
return a * b
elif opcion == 4:
return a / b
else:
return "Opcion Incorrecta"
calcular(3, 5, 3)
//this function return a value and recibe two parameters
function suma(a, b) {
return a + b;
}
//this function no return a value and recibe two parameters
function resta(a, b) {
return a - b;
}
//this function return a value and recibe two parameters
function multiplicacion(a, b) {
return a * b;
}
//this function return a value and recibe two parameters
function division(a, b) {
return a / b;
}
//this function return a value and recibe two parameters
function potencia(a, b) {
let result = 1;
for (let i = 1; i <= b; i++) {
result *= a;
}
return result;
}
//this function return a value and recibe three parameters
function operacion(a, b, c) {
return a(b, c);
}
//this function return a value and recibe two parameters
function modulo(a, b) {
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
return a / b
<?php
$n1 = $_POST['n1'];
$n2 = $_POST['n2'];
$op = $_POST['op'];
switch($op) {
case 'suma':
echo (int)$n1 + (int)$n2;
break;
case 'resta':
echo (int)$n1 - (int)$n2;
break;
case 'multiplicacion':
echo (int)$n1 * (int)$n2;
break;
case 'division':
echo (int)$n1 / (int)$n2;
break;
}
?>
Script
function suma(valor1, valor2) {
return valor1 + valor2;
}
function resta(valor1, valor2) {
return valor1 - valor2;
}
function multiplicacion(valor1, valor2) {
return valor1 * valor2;
}
function division(valor1, valor2) {
return valor1 / valor2;
}
function raizCuadrada(valor1) {
return Math.sqrt(valor1);
}
function porcentaje(valor1) {
return valor1 / 100;
}
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
return a / b
print("Please select operation -\n" \
"1. Add\n" \
"2. Subtract\n" \
"3. Multiply\n" \
"4. Divide\n")
select = input("Select operations form 1, 2, 3, 4 :")
number_1 = int(input("Enter first number: "))
number_2 = int(input("Enter second number: "))
if select == '1':
print(number_1, "+", number_2, "=",
add(number_1, number_2))
elif select == '2':
print(number_1, "-", number_2, "=",
subtract(number_1, number_2))
elif select == '
def bot():
return "Hello, this is a Mathematical Bot"
public static int sumar(int a, int b) {
return a + b;
}
public static int restar(int a, int b) {
return a - b;
}
public static int multiplicar(int a, int b) {
return a * b;
}
public static int dividir(int a, int b) {
return a / b;
}
import telepot
import os
def handle(msg):
chat_id = msg['chat']['id']
command = msg['text']
print(msg)
print('Got command: %s' % command)
if command == '/start':
bot.sendMessage(chat_id, "Bienvenido al bot de calculadora \n \n para empezar a usarlo presiona los comandos")
bot.sendMessage(chat_id, " /add - Sumar \n /sub - Resta \n /mul - Multiplicacion \n /div - Division")
bot.sendMessage(chat_id, "Instrucciones: \n \n 1 - Primero debes escribir el comando \n 2 - Luego dos numeros separados por un espacio \n 3 - Ejemplo: /add 2 4 ")
elif command == '/add':
bot.sendMessage(chat_id, "Ingrese dos numeros \n \n Ejemplo: /add 2 4
Script
function add(a, b) {
return a + b;
}
function subtract(a, b) {
return a - b;
}
function multiply(a, b) {
return a * b;
}
function divide(a, b) {
return a / b;
}
def calculadora(a, b, operador):
if operador == "+":
return add(a, b)
elif operador == "-":
return subtract(a, b)
elif operador == "*":
return multiply(a, b)
elif operador == "/":
return divide(a, b)
else:
print("Operador no soportado")
calculadora(1, 2, "+")