def handle(req): if not req: return help calc = SimpleCalculator() calc.run(req) return calc.lcd
def compute(request, input_str=""): """ Computes the input_str :param request: The HTTP request object (given by django) :param input_str: string of operator and arguments :return: JSON responsse with the result """ if not input_str: return JsonResponse( { 'status': 'false', 'message': "Give an operation, e.g 2+2 or ceil20.01" }, status=400) # Give an extra space between the operators (more user friendly) operators = ['+', '-', '*', '/', 'fmod', 'abs', 'fabs', 'ceil'] for o in operators: input_str = input_str.replace(o, ' {} '.format(o)) c = SimpleCalculator() c.run(input_str) return JsonResponse({'status': 'success', 'result': c.lcd})
def calculate(statement): calculator = SimpleCalculator() calculator.run(statement) print(f'simplecalculator log: {calculator.log}') if calculator.log[-1] == 'result: Error': raise InputSyntaxError # The calculator.log is a list of string. The result is the last element. return calculator.log[-1].split(' ')[1]
def calc(text): """based on the input text, return the operation result""" try: c = SimpleCalculator() c.run(text) return c.log[-1] except Exception as e: print(e) return 0.0
def get(self, calculator_input): """ Take an input string and calculate its result with a simple calculator. The input should contain spaces between numbers and operators. """ calculator = SimpleCalculator() calculator.run(calculator_input) return {'result_of_calculation': calculator.reg_1}
def calc(text): """based on the input text, return the operation result""" try: c = SimpleCalculator() c.run(text) #return c.log[-1] return ": This is a test (" + c.log[-1] + ")" except Exception as e: print(e) return 0.0
def evaluate(a): """ Evaluation operation Keyword arguments: a -- the first operand Returns: result of expression evaluation """ c = SimpleCalculator() c.run(a) print(c.log) return c.lcd
def calc(self) -> Response: if "calculation" not in self.request.json_body: response_text = json.dumps({"error": "no calculation request given"}) return Response(response_text) c = SimpleCalculator() c.run(self.request.json_body["calculation"]) if any("ignored" in e for e in c.log): response_text = json.dumps(({"error": f"Invalid calculation given: {[e for e in c.log if 'ignored' in e][0]}"})) return Response(response_text) result = [e for e in c.log if 'result' in e] if len(result) == 1: result[0] = result[0].replace("result: ", "") response_text = json.dumps({"result": result[0]}) return Response(response_text) response_text = json.dumps({"error": "unknown exception (calculation too complex?)"}) return Response(response_text)
import webbrowser as wb import numpy import tflearn import json import keyboard from datetime import datetime import pickle import speech_recognition as sr from gtts import gTTS from playsound import playsound import os import requests from os import path import time from calculator.simple import SimpleCalculator cal = SimpleCalculator() import os.path bad_responce = [ 'I could not understand the question', 'I dont know how to respond', "I do not know the answer to that" ] first_run = True with open('intents.json') as file: data = json.load(file) try: with open('data.pickle', 'rb') as f: words, lables, training, output = pickle.load(f) first_run = False
def calc(rawtxt): expression = rawtxt.replace('mafs', '') proc = SimpleCalculator() proc.run(expression) ans = proc.lcd return ans
def calculate_v1(request: Request) -> CalculateResponse: expression = request.openapi_validated.body.expression calc = SimpleCalculator() calc.run(expression) return CalculateResponse(result=calc.lcd)
def step_impl(context, inp): print(u'STEP: Cuando paso "{}" a la calculadora'.format(inp)) c = SimpleCalculator() c.run(inp) context.result = c.lcd
def calculator(self): calculator = SimpleCalculator() #FIXME: Add exception handling calc = self.request.json_body["input"] calculator.run(calc) return {'result': str(calculator.lcd)}