From f9c25dad09f1c0d53b928408bb3b14ffca87d8b5 Mon Sep 17 00:00:00 2001 From: ltcptgeneral <35508619+ltcptgeneral@users.noreply.github.com> Date: Wed, 29 Apr 2020 12:58:44 -0500 Subject: [PATCH] 3 --- .../analysis-amd64/analysis/equation.ipynb | 51 +++++++++++++------ 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/analysis-master/analysis-amd64/analysis/equation.ipynb b/analysis-master/analysis-amd64/analysis/equation.ipynb index 33772754..0a4f162d 100644 --- a/analysis-master/analysis-amd64/analysis/equation.ipynb +++ b/analysis-master/analysis-amd64/analysis/equation.ipynb @@ -2,51 +2,70 @@ "cells": [ { "cell_type": "code", - "execution_count": 148, + "execution_count": 61, "metadata": {}, "outputs": [], "source": [ - "import re" + "import re\n", + "from decimal import Decimal\n", + "from functools import reduce" ] }, { "cell_type": "code", - "execution_count": 155, + "execution_count": 56, "metadata": {}, "outputs": [], - "source": [ - "string = \"3+45+-5\"" - ] + "source": [] }, { "cell_type": "code", - "execution_count": 156, + "execution_count": 62, "metadata": {}, "outputs": [], "source": [ "def add(string):\n", " while(len(re.findall(\"[+]{1}[-]?\", string)) != 0):\n", - " string = re.sub(\"\\d+[+]{1}[-]?\\d+\", str(sum([int(i) for i in re.split(\"[+]{1}\", re.search(\"\\d+[+]{1}[-]?\\d+\", string).group())])), string, 1)\n", + " string = re.sub(\"[-]?\\d+[.]?\\d*[+]{1}[-]?\\d+[.]?\\d*\", str(sum([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": 157, + "execution_count": 63, + "metadata": {}, + "outputs": [], + "source": [ + "def multiply(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": 69, "metadata": {}, "outputs": [ { - "output_type": "execute_result", - "data": { - "text/plain": "'43'" - }, - "metadata": {}, - "execution_count": 157 + "output_type": "stream", + "name": "stdout", + "text": "-29\n" } ], "source": [ - "add(string)" + "string = \"-3+4+-5*6\"\n", + "string = multiply(string)\n", + "string = add(string)\n", + "print(string)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": {