Skip to content

Calculator for basic operations (+,-,*,/) which is able to have english words as source of the operation

Notifications You must be signed in to change notification settings

JoseReisinho/python-basic-calculator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Basic Calculator

Credits

M. Bonet and Greg Hewgill (https://github.com/ghewgill/text2num)

Definition

Calculator which supports the basic operations on integers. 
It works with English words for numbers and operators.

The calculator input is read from stdin consisting of one expression 
per line and terminated by an empty line. The results are written to 
stdout, one result per line. See sample input and output.

In case of errors it should emit "ERROR" as the calculation result. 
If any intermediate result is outside the range of valid numbers this 
is also considered an error.

Valid Operators:
	+, plus
	-, minus
	*, times
	/, divided by

Numbers all integers in the range -9.999.999 to 9.999.999 (inclusive) 
the English words for all integers in the above range, e.g. "minus two thousand and one"

Sample Input            Sample output
--------------          ---------------
7 + 2                   9
8/3                     2
3 divided by 0          ERROR
twenty one times 2      42
<empty line>

How to run

Run application:
dev@localhost:~/home/calc$ ./calc.py
or
dev@localhost:~/home/calc$ python calc.py

Run tests:
dev@localhost:~/home/calc$ nosetests tests.py

About

Calculator for basic operations (+,-,*,/) which is able to have english words as source of the operation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%