Friday, April 01, 2005
Basic Python Calculator - pycalc
Inspired by the first version of my calculator (in c#), I went on with the same application in python but using slightly different logic during the expression evaluation. Well, it was really challenging to sit overnight to get the code done. Get the code here.View AlgorithmHide Algorithm
View OutputHide Output
Here is the simple Algorithm that I have used:
1. Build a list of tokens from input expression.
2. Evaluate all the subexpression in the list and replace it with the result.
3. Now, evaluate the right hand side of assignment operator (if present)
and replace it with result.
4. Finally, evaluate the remaining expression in the list.
The Calculator output:
[prasad@prasad pycalc]$ ./pycalc.py
Basic Calculator Application, from Prasad.A
Type 'quit' to terminate
Prasad, I tried to use your js code which u have written for "show algo", "hide" but the formatting goes for a toss. Once we click on "show algo", the text there is not similar to the text above "show algo". So to preserve this do we have to write another div class. The reason I am asking this is that I wanted something like "Read more >>" link for lengthy articles..Or is there any such tag available in blogspot like in lj ?Post a Comment