{"id":18004735,"url":"https://github.com/goodmanwen/calculateexpression","last_synced_at":"2025-07-18T10:06:37.388Z","repository":{"id":57416873,"uuid":"153923704","full_name":"GoodManWEN/CalculateExpression","owner":"GoodManWEN","description":"A simple calculator for string expressions","archived":false,"fork":false,"pushed_at":"2018-10-22T17:02:02.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-14T02:04:38.506Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GoodManWEN.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-20T16:10:18.000Z","updated_at":"2020-03-03T05:28:44.000Z","dependencies_parsed_at":"2022-08-23T15:51:24.925Z","dependency_job_id":null,"html_url":"https://github.com/GoodManWEN/CalculateExpression","commit_stats":null,"previous_names":["goodmanwen/calculate_expression"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/GoodManWEN/CalculateExpression","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodManWEN%2FCalculateExpression","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodManWEN%2FCalculateExpression/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodManWEN%2FCalculateExpression/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodManWEN%2FCalculateExpression/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GoodManWEN","download_url":"https://codeload.github.com/GoodManWEN/CalculateExpression/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodManWEN%2FCalculateExpression/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265738431,"owners_count":23820162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-30T00:15:47.363Z","updated_at":"2025-07-18T10:06:37.364Z","avatar_url":"https://github.com/GoodManWEN.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Calculate Expression\n### A simple calculator dealing with expressions in string type ,using stack data structure.\n\n# Features\n\n - You can custom each operator's priority and behavior.\n - Expressions both with and without algebras are supported.\n \n# Caution\n\n - spaces in input expressions will be removed while processing.\n - each expression will be converted into (expression) before processing to avoid empty stack problems.\n\n# Installation\n\n    $ pip install calculate-expression\n\n#####   \\* since using f-string for formating ,could only be installed on python3.6+\n\n# Usage\n\ninitialize a standard calculator:\n(optional parameters \"rule\" \u0026 \"regularization\")\n\n    from calculate_expression import ce\n    standard = ce.Calculator()\n\nYou can custom your own operator sets ,default ones like this:\n\n    # \"operator\":(priority,'behavior')\n    # behavior is string type ,thus we can easily check its logic\n    # we will use eval() to convert it into function later\n    rules = { '+' : (0 ,'lambda x,y:x+y') ,\n             '-' : (0 ,'lambda x,y:x-y') ,\n             '*' : (1 ,'lambda x,y:x*y') ,\n             '/' : (1 ,'lambda x,y:x/y') , \n             '^' : (2 ,'lambda x,y:x**y') }\n    standard = ce.Calculator(rules)\n    \n\n#####   \\* once new operator is added ,regularization function may need to be modified commensurately.\n#####   \\* default regularization function: `lambda x:x.replace(\"**\",\"^\").replace('\\\\','/')`\n\nYou can check operate rules and regularfunction like this ,\nThus you can easily modify it.\n\n    \u003e standard.printinfo()\n    \u003e \n    \u003e defalut_regularization_function = lambda x:x.replace('**','^').replace('\\\\','/')\n    \u003e \n    \u003e rules = { '+' : (0, 'lambda x,y:x+y') ,\n    \u003e           '-' : (0, 'lambda x,y:x-y') ,\n    \u003e           '*' : (1, 'lambda x,y:x*y') ,\n    \u003e           '/' : (1, 'lambda x,y:x/y') ,\n    \u003e           '^' : (2, 'lambda x,y:x**y') }\n    \u003e\n\nTry a simple calculate\n\n    \u003e print( standard.calculate('1 + 2 * 3') )\n    \u003e 7\n\nAlgebra is supported\n\n    \u003e print( standard.calculate('a + b * c' ,a = 1 ,b = 2 ,c = 3) )\n    \u003e 7\n\nOnce introduced ,algebras will be stored in whose object's attribute as a dictionary ,\nIt will remain until it's updated.\n\n    \u003e print( standard.calculate('' ,a = 1 ,b = 2 ,c = 3 ,d = 4 ,e = 1.6) ) # update params only \n    \u003e None\n    \u003e print( standard.calculate('d ** 4 / e') )\n    \u003e 160\n    \u003e print( standard.calculate('d ** 4 / e' ,e = 0.1625) )\n    \u003e 1575.3846153846152\n\nHave fun.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodmanwen%2Fcalculateexpression","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoodmanwen%2Fcalculateexpression","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodmanwen%2Fcalculateexpression/lists"}