From 429d3eb42c6aeb7af9002c457b02856bc64f8e46 Mon Sep 17 00:00:00 2001 From: ltcptgeneral <35508619+ltcptgeneral@users.noreply.github.com> Date: Wed, 29 Apr 2020 22:34:43 -0500 Subject: [PATCH] 6 --- .../analysis-amd64/analysis/equation.ipynb | 68 ++++++++++++------- 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/analysis-master/analysis-amd64/analysis/equation.ipynb b/analysis-master/analysis-amd64/analysis/equation.ipynb index 58b5c57f..b5ebf646 100644 --- a/analysis-master/analysis-amd64/analysis/equation.ipynb +++ b/analysis-master/analysis-amd64/analysis/equation.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 28, + "execution_count": 48, "metadata": {}, "outputs": [], "source": [ @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 49, "metadata": {}, "outputs": [], "source": [ @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 50, "metadata": {}, "outputs": [], "source": [ @@ -45,7 +45,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 51, "metadata": {}, "outputs": [], "source": [ @@ -57,17 +57,37 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 52, "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": "-30\n" - } - ], + "outputs": [], "source": [ - "def eval(string):\n", + "def div(string):\n", + " while(len(re.findall(\"[/]{1}[-]?\", string)) != 0):\n", + " string = re.sub(\"[-]?\\d+[.]?\\d*[/]{1}[-]?\\d+[.]?\\d*\", str(reduce((lambda x, y: x / y), [Decimal(i) for i in re.split(\"[/]{1}\", re.search(\"[-]?\\d+[.]?\\d*[/]{1}[-]?\\d+[.]?\\d*\", string).group())])), string, 1)\n", + " return string" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [], + "source": [ + "def exp(string):\n", + " while(len(re.findall(\"[\\^]{1}[-]?\", string)) != 0):\n", + " string = re.sub(\"[-]?\\d+[.]?\\d*[\\^]{1}[-]?\\d+[.]?\\d*\", str(reduce((lambda x, y: x ** y), [Decimal(i) for i in re.split(\"[\\^]{1}\", re.search(\"[-]?\\d+[.]?\\d*[\\^]{1}[-]?\\d+[.]?\\d*\", string).group())])), string, 1)\n", + " return string" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [], + "source": [ + "def evaluate(string):\n", + " string = exp(string)\n", + " string = div(string)\n", " string = mul(string)\n", " string = sub(string)\n", " string = add(string)\n", @@ -76,29 +96,27 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 70, "metadata": {}, "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "-128+0.8\n" + }, { "output_type": "execute_result", "data": { - "text/plain": "-22" + "text/plain": "'-127.2'" }, "metadata": {}, - "execution_count": 34 + "execution_count": 70 } ], "source": [ - "string = \"2--3+4-5*6-1\"\n", - "eval(string)" + "string = \"8^2*4/-2+0.8\"\n", + "evaluate(string)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": {