Code Monkey home page Code Monkey logo

prefix_infix_calculator's Introduction

Prefix & Infix Calculator

A calculator that accepts numerical calculations in prefix and infix notations, as specified in https://github.com/Kheiron-Medical/swe_take_home_exercise.

I follow the assumptions provided and distinguish between the two notations given the input expression.

  • calculator.py contains the functionality for parts 1 and 2 (prefix and infix calculation)
  • calculator_api.py creates a RESTful API served on http://127.0.0.1:5000/, where the user can access and interact through a user interface.
  • test_calculator.py contains test cases for the functionality of calculator.py.

Installation

This project is implemented using Python 3.8.3 and pip version 19.2.3 and uses Flask to create a RESTful API and serve a simple user interface.

Create a local environment and install the requirements:

python3 -m venv .env
source .env/bin/activate
pip install -r requirements.txt

Run the app

Command line

The calculator can be run through the command line with either one of these two options:

  1. Pass the expression as an argument through --input when running the file:

python calculator.py --input '- 12 * 2 6'

  1. Run the file without passing any arguments and wait for the prompt. This way you can test many expressions without rerunning the file: python calculator.py

REST API

Export the FLASK_APP environment variable and run the API locally.

export FLASK_APP=calculator_api.py
flask run

The API is now running on http://127.0.0.1:5000/, where the user can input an expression and view the result or any error messages.

Testing

Run pytest to run all the tests written in test_calculator.py. The tests calculate all the examples provided in https://github.com/Kheiron-Medical/swe_take_home_exercise, as well as corner cases.

prefix_infix_calculator's People

Contributors

marinapts avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.